Member.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. namespace app\controller\api;
  3. use laytp\controller\Api;
  4. use app\service\api\UserServiceFacade;
  5. use app\service\ConfServiceFacade;
  6. // use app\service\MessageSystemServiceFacade;
  7. use app\service\BillServiceFacade;
  8. use think\facade\Db;
  9. /**
  10. * 会员次数相关
  11. * @ApiWeigh (90)
  12. */
  13. class Member extends Api
  14. {
  15. // 无需无需登录的接口,*表示全部
  16. public $noNeedLogin = ['list','detail','customized'];
  17. protected function _initialize()
  18. {
  19. $this->model = new \app\model\Member();
  20. }
  21. // 列表
  22. public function list(){
  23. global $_GPC;
  24. $type = $this->request->param('type',1);
  25. $order = ['sort'=>'desc','id' => 'desc'];
  26. $where = ['uniacid'=>$_GPC['uniacid'],'type'=>$type,'status'=>1 ];
  27. $data = $this->model->where($where)->order($order)->select()->toArray();
  28. if(!$data){
  29. return $this->error('数据获取失败');
  30. }
  31. return $this->success('数据获取成功', $data);
  32. }
  33. /**
  34. * 详情
  35. * @param $file
  36. * @return array|boolean
  37. */
  38. public function detail()
  39. {
  40. $return = [];
  41. $id = $this->request->param('id');
  42. $info = $this->model->find($id);
  43. if(!$info){
  44. return $this->error('详情获取失败');
  45. }
  46. return $this->success('获取成功', $info);
  47. }
  48. public function addCoin(){
  49. global $_GPC;
  50. $post = $this->request->post();
  51. $type = $this->request->post('type','video');
  52. $loginUserInfo = UserServiceFacade::getUserInfo();
  53. if(!$type){
  54. return $this->error('正确上传type',2);
  55. }
  56. $conf = ConfServiceFacade::groupGet('system.plan', 0);
  57. $countToday = \app\model\Bill::where(['uid'=>$loginUserInfo['id'],'type'=>$type ])->where('create_time','>',date('Y-m-d 00:00:00'))->count();
  58. $typeText='';
  59. switch($type){
  60. case 'video':
  61. $typeText ='观看激励视频获得奖励';
  62. $coin = $conf['video'];
  63. if($countToday >= $conf['video_limit']){
  64. return $this->error('今日已达获取上限,请明天再试');
  65. }
  66. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','观看激励视频获得奖励');
  67. break;
  68. case 'sign':
  69. $typeText ='签到获得奖励';
  70. $coin = $conf['sign'];
  71. if($countToday>=1){
  72. return $this->error('今日已达获取上限,请明天再试');
  73. }
  74. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','签到获得奖励');
  75. break;
  76. case 'share':
  77. $typeText ='分享获得奖励';
  78. $coin = $conf['share'];
  79. if($countToday >= $conf['share_limit']){
  80. return $this->error('今日已达获取上限,请明天再试');
  81. }
  82. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','分享获得奖励');
  83. break;
  84. }
  85. $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$coin)->update();
  86. if(!$balanceRes){
  87. return $this->error('增加金币失败');
  88. }
  89. BillServiceFacade::record(1,$coin,$type,$typeText,$loginUserInfo['id'],$_GPC['uniacid']);
  90. return $this->success('数据获取成功', $balanceRes);
  91. }
  92. public function open(){
  93. global $_GPC;
  94. $post = $this->request->post();
  95. $orderid = $this->request->post('orderid',0);
  96. if(!$orderid){
  97. return $this->error('请上传订单编号');
  98. }
  99. $orderInfo = \app\model\Order::where('id', '=', $orderid)->find();
  100. $linkId = $orderInfo['link_id'];
  101. $MemberInfo = $this->model->where('id', '=', $linkId)->find();
  102. $loginUserInfo = UserServiceFacade::getUserInfo();
  103. // $balance = $loginUserInfo['vip_time'] + strtotime("+".$MemberInfo['days']."days");
  104. $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->update(['vip_time' => $balance]);
  105. if(!$balanceRes){
  106. return $this->error('数据获取失败');
  107. }
  108. return $this->success('数据获取成功', $balanceRes);
  109. }
  110. public function reduce(){
  111. $loginUserInfo = UserServiceFacade::getUserInfo();
  112. $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])
  113. ->dec('times', 1)
  114. ->update();
  115. return $this->success('数据获取成功',$balanceRes);
  116. }
  117. public function reduceCoin(){
  118. global $_GPC;
  119. $post = $this->request->post();
  120. $type = $this->request->post('type','');
  121. $role = $this->request->post('role','');
  122. $linkId = $this->request->post('link_id',0);
  123. $incrementId = $this->request->post('increment_id',0);
  124. $loginUserInfo = UserServiceFacade::getUserInfo();
  125. if(!$type){
  126. return $this->error('请上传类型type',2);
  127. }
  128. if(!$linkId){
  129. return $this->error('请上传ID',2);
  130. }
  131. if(!$role){
  132. return $this->error('请填写要查询的role类型',2);
  133. }
  134. if($type == 'contact'){
  135. $modelCall = new \app\model\Call();
  136. $coin = ConfServiceFacade::get('system.plan.lock_'.$role);
  137. if($role == 'job'){
  138. $phone = \app\model\Job::where('id',$linkId)->value('phone');
  139. }else{
  140. $phone = \app\model\Worker::where('id',$linkId)->value('phone');
  141. }
  142. if($coin == 0){
  143. $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
  144. return $this->success('查看成功',$phone);
  145. }
  146. if($loginUserInfo['coin'] <$coin){
  147. return $this->error('您的次数不足');
  148. }
  149. $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update();
  150. if(!$res){
  151. return $this->error('数据操作失败');
  152. }
  153. $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
  154. BillServiceFacade::record(0,$coin,$type,'获得联系方式',$loginUserInfo['id'],$_GPC['uniacid']);
  155. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','获得联系方式消耗次数'.$coin);
  156. return $this->success('消费次数成功',$phone);
  157. }elseif($type == 'top'){
  158. if(!$incrementId){
  159. return $this->error('请上传增值服务ID',2);
  160. }
  161. $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
  162. if(!$incrementInfo){
  163. return $this->error('获取增值服务信息失败');
  164. }
  165. if($loginUserInfo['coin'] < $incrementInfo['price']){
  166. return $this->error('次数不足');
  167. }
  168. $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
  169. if($role == 'job'){
  170. $response = \app\model\Job::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
  171. }else{
  172. $response = \app\model\Worker::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
  173. }
  174. BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费置顶服务',$loginUserInfo['id'],$_GPC['uniacid']);
  175. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','置顶服务消耗次数'.$incrementInfo['price']);
  176. return $this->success('消费次数成功',$incrementInfo);
  177. }elseif($type == 'refresh'){
  178. if(!$incrementId){
  179. return $this->error('请上传增值服务ID',2);
  180. }
  181. $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
  182. if(!$incrementInfo){
  183. return $this->error('获取增值服务信息失败');
  184. }
  185. if($loginUserInfo['coin'] <$incrementInfo['price']){
  186. return $this->error('您的次数不足');
  187. }
  188. $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
  189. if($role == 'job'){
  190. $response = \app\model\Job::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
  191. }else{
  192. $response = \app\model\Worker::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
  193. }
  194. BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费刷新服务',$loginUserInfo['id'],$_GPC['uniacid']);
  195. // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','刷新服务消耗次数'.$incrementInfo['price']);
  196. return $this->success('消费次数成功',$res);
  197. }
  198. }
  199. // 列表
  200. public function bill(){
  201. global $_GPC;
  202. $modelBill = new \app\model\Bill();
  203. $loginUserInfo = UserServiceFacade::getUserInfo();
  204. $order = ['id' => 'desc'];
  205. $where = ['uid' => $loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
  206. $limit = $this->request->param('limit', 10);
  207. $data = $modelBill->order($order)->where($where)->paginate($limit)->toArray();
  208. if(!$data){
  209. return $this->error('数据获取失败');
  210. }
  211. return $this->success('数据获取成功', $data);
  212. }
  213. // 列表
  214. public function kami(){
  215. global $_GPC;
  216. $modelKami = new \app\model\Kami();
  217. $code = $this->request->post('code',0);
  218. if(!$code){
  219. return $this->error('请输入卡密');
  220. }
  221. $loginUserInfo = UserServiceFacade::getUserInfo();
  222. $info = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->find();
  223. if(!$info){
  224. return $this->error('未查询到卡密信息');
  225. }
  226. if($info['status'] == 1){
  227. return $this->error('此卡已被启用过');
  228. }
  229. $res = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->update(['status'=>1]);
  230. $text = '使用卡密';
  231. if($info[ 'type'] == 1){
  232. $text = '使用卡密兑换次数';
  233. \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$info['value'])->update();
  234. }elseif($info['type'] == 2){
  235. $text = '使用卡密兑换时长';
  236. if($loginUserInfo['vip_time'] < time()){
  237. $balance = strtotime("+".$info['value']."days");
  238. }else{
  239. // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
  240. $balance = $loginUserInfo['vip_time'] + $info['value']*24*60*60;
  241. }
  242. $updateRes2 = \app\model\User::where('id', '=', $loginUserInfo['id'])->update(['vip_time' => $balance]);
  243. }
  244. $modelKami->where(['id'=>$info['id']])->inc('uid',$loginUserInfo['id'])->update();
  245. BillServiceFacade::record(1,$info['value'],'pay_member',$text,$loginUserInfo['id'],$_GPC['uniacid']);
  246. return $this->success('兑换成功', $info);
  247. }
  248. public function customized()
  249. {
  250. global $_GPC;
  251. $unionid = $this->request->post('unionid','');
  252. $type = $this->request->post('type','addCoin');
  253. $coin = $this->request->post('coin',0);
  254. $day = $this->request->post('day',0);
  255. if(!$unionid){
  256. return $this->error('请上传uninid');
  257. }
  258. $userInfo = \app\model\User::where(['unionid'=>$unionid])->find();
  259. if(!$userInfo){
  260. return $this->error('未查询到此用户信息');
  261. }
  262. if($type == 'addCoin'){
  263. $balanceRes = \app\model\User::where(['id'=>$userInfo['id']])->inc('coin',$coin)->update();
  264. if(!$balanceRes){
  265. return $this->error('增加金币失败');
  266. }
  267. BillServiceFacade::record(1,$coin,'pay_member','通过接口充值点数',$userInfo['id'],$_GPC['uniacid']);
  268. }elseif($type == 'addVip'){
  269. if($userInfo['vip_time'] < time()){
  270. $balance = strtotime("+".$day."days");
  271. }else{
  272. // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
  273. $balance = $userInfo['vip_time'] + $day*24*60*60;
  274. }
  275. $balanceRes = \app\model\User::where('id', '=', $userInfo['id'])->update(['vip_time' => $balance]);
  276. BillServiceFacade::record(1,$day,'pay_member','通过接口充值时长',$userInfo['id'],$_GPC['uniacid']);
  277. }
  278. return $this->success('成功', $balanceRes);
  279. }
  280. }