123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?php
- namespace app\controller\api;
- use laytp\controller\Api;
- use app\service\api\UserServiceFacade;
- use app\service\ConfServiceFacade;
- // use app\service\MessageSystemServiceFacade;
- use app\service\BillServiceFacade;
- use think\facade\Db;
- /**
- * 会员次数相关
- * @ApiWeigh (90)
- */
- class Member extends Api
- {
- // 无需无需登录的接口,*表示全部
- public $noNeedLogin = ['list','detail','customized'];
- protected function _initialize()
- {
- $this->model = new \app\model\Member();
- }
- // 列表
- public function list(){
- global $_GPC;
- $type = $this->request->param('type',1);
- $order = ['sort'=>'desc','id' => 'desc'];
- $where = ['uniacid'=>$_GPC['uniacid'],'type'=>$type,'status'=>1 ];
- $data = $this->model->where($where)->order($order)->select()->toArray();
- if(!$data){
- return $this->error('数据获取失败');
- }
- return $this->success('数据获取成功', $data);
- }
- /**
- * 详情
- * @param $file
- * @return array|boolean
- */
- public function detail()
- {
- $return = [];
- $id = $this->request->param('id');
- $info = $this->model->find($id);
- if(!$info){
- return $this->error('详情获取失败');
- }
- return $this->success('获取成功', $info);
- }
- public function addCoin(){
- global $_GPC;
- $post = $this->request->post();
- $type = $this->request->post('type','video');
- $loginUserInfo = UserServiceFacade::getUserInfo();
- if(!$type){
- return $this->error('正确上传type',2);
- }
- $conf = ConfServiceFacade::groupGet('system.plan', 0);
- $countToday = \app\model\Bill::where(['uid'=>$loginUserInfo['id'],'type'=>$type ])->where('create_time','>',date('Y-m-d 00:00:00'))->count();
- $typeText='';
- switch($type){
- case 'video':
- $typeText ='观看激励视频获得奖励';
- $coin = $conf['video'];
- if($countToday >= $conf['video_limit']){
- return $this->error('今日已达获取上限,请明天再试');
- }
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','观看激励视频获得奖励');
- break;
- case 'sign':
- $typeText ='签到获得奖励';
- $coin = $conf['sign'];
- if($countToday>=1){
- return $this->error('今日已达获取上限,请明天再试');
- }
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','签到获得奖励');
- break;
- case 'share':
- $typeText ='分享获得奖励';
- $coin = $conf['share'];
- if($countToday >= $conf['share_limit']){
- return $this->error('今日已达获取上限,请明天再试');
- }
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','分享获得奖励');
- break;
- }
- $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$coin)->update();
- if(!$balanceRes){
- return $this->error('增加金币失败');
- }
- BillServiceFacade::record(1,$coin,$type,$typeText,$loginUserInfo['id'],$_GPC['uniacid']);
- return $this->success('数据获取成功', $balanceRes);
- }
- public function open(){
- global $_GPC;
- $post = $this->request->post();
- $orderid = $this->request->post('orderid',0);
- if(!$orderid){
- return $this->error('请上传订单编号');
- }
- $orderInfo = \app\model\Order::where('id', '=', $orderid)->find();
- $linkId = $orderInfo['link_id'];
- $MemberInfo = $this->model->where('id', '=', $linkId)->find();
- $loginUserInfo = UserServiceFacade::getUserInfo();
- // $balance = $loginUserInfo['vip_time'] + strtotime("+".$MemberInfo['days']."days");
- $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->update(['vip_time' => $balance]);
- if(!$balanceRes){
- return $this->error('数据获取失败');
- }
- return $this->success('数据获取成功', $balanceRes);
- }
- public function reduce(){
- $loginUserInfo = UserServiceFacade::getUserInfo();
- $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])
- ->dec('times', 1)
- ->update();
- return $this->success('数据获取成功',$balanceRes);
- }
- public function reduceCoin(){
- global $_GPC;
- $post = $this->request->post();
- $type = $this->request->post('type','');
- $role = $this->request->post('role','');
- $linkId = $this->request->post('link_id',0);
- $incrementId = $this->request->post('increment_id',0);
- $loginUserInfo = UserServiceFacade::getUserInfo();
- if(!$type){
- return $this->error('请上传类型type',2);
- }
- if(!$linkId){
- return $this->error('请上传ID',2);
- }
- if(!$role){
- return $this->error('请填写要查询的role类型',2);
- }
- if($type == 'contact'){
- $modelCall = new \app\model\Call();
- $coin = ConfServiceFacade::get('system.plan.lock_'.$role);
- if($role == 'job'){
- $phone = \app\model\Job::where('id',$linkId)->value('phone');
- }else{
- $phone = \app\model\Worker::where('id',$linkId)->value('phone');
- }
- if($coin == 0){
- $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
- return $this->success('查看成功',$phone);
- }
- if($loginUserInfo['coin'] <$coin){
- return $this->error('您的次数不足');
- }
- $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update();
- if(!$res){
- return $this->error('数据操作失败');
- }
- $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
- BillServiceFacade::record(0,$coin,$type,'获得联系方式',$loginUserInfo['id'],$_GPC['uniacid']);
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','获得联系方式消耗次数'.$coin);
- return $this->success('消费次数成功',$phone);
- }elseif($type == 'top'){
- if(!$incrementId){
- return $this->error('请上传增值服务ID',2);
- }
- $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
- if(!$incrementInfo){
- return $this->error('获取增值服务信息失败');
- }
- if($loginUserInfo['coin'] < $incrementInfo['price']){
- return $this->error('次数不足');
- }
- $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
- if($role == 'job'){
- $response = \app\model\Job::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
- }else{
- $response = \app\model\Worker::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
- }
- BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费置顶服务',$loginUserInfo['id'],$_GPC['uniacid']);
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','置顶服务消耗次数'.$incrementInfo['price']);
- return $this->success('消费次数成功',$incrementInfo);
- }elseif($type == 'refresh'){
- if(!$incrementId){
- return $this->error('请上传增值服务ID',2);
- }
- $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
- if(!$incrementInfo){
- return $this->error('获取增值服务信息失败');
- }
- if($loginUserInfo['coin'] <$incrementInfo['price']){
- return $this->error('您的次数不足');
- }
- $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
- if($role == 'job'){
- $response = \app\model\Job::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
- }else{
- $response = \app\model\Worker::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
- }
- BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费刷新服务',$loginUserInfo['id'],$_GPC['uniacid']);
- // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','刷新服务消耗次数'.$incrementInfo['price']);
- return $this->success('消费次数成功',$res);
- }
- }
- // 列表
- public function bill(){
- global $_GPC;
- $modelBill = new \app\model\Bill();
- $loginUserInfo = UserServiceFacade::getUserInfo();
- $order = ['id' => 'desc'];
- $where = ['uid' => $loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
- $limit = $this->request->param('limit', 10);
- $data = $modelBill->order($order)->where($where)->paginate($limit)->toArray();
- if(!$data){
- return $this->error('数据获取失败');
- }
- return $this->success('数据获取成功', $data);
- }
- // 列表
- public function kami(){
- global $_GPC;
- $modelKami = new \app\model\Kami();
- $code = $this->request->post('code',0);
- if(!$code){
- return $this->error('请输入卡密');
- }
- $loginUserInfo = UserServiceFacade::getUserInfo();
- $info = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->find();
- if(!$info){
- return $this->error('未查询到卡密信息');
- }
- if($info['status'] == 1){
- return $this->error('此卡已被启用过');
- }
- $res = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->update(['status'=>1]);
- $text = '使用卡密';
- if($info[ 'type'] == 1){
- $text = '使用卡密兑换次数';
- \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$info['value'])->update();
- }elseif($info['type'] == 2){
- $text = '使用卡密兑换时长';
- if($loginUserInfo['vip_time'] < time()){
- $balance = strtotime("+".$info['value']."days");
- }else{
- // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
- $balance = $loginUserInfo['vip_time'] + $info['value']*24*60*60;
- }
- $updateRes2 = \app\model\User::where('id', '=', $loginUserInfo['id'])->update(['vip_time' => $balance]);
- }
- $modelKami->where(['id'=>$info['id']])->inc('uid',$loginUserInfo['id'])->update();
- BillServiceFacade::record(1,$info['value'],'pay_member',$text,$loginUserInfo['id'],$_GPC['uniacid']);
- return $this->success('兑换成功', $info);
- }
- public function customized()
- {
- global $_GPC;
- $unionid = $this->request->post('unionid','');
- $type = $this->request->post('type','addCoin');
- $coin = $this->request->post('coin',0);
- $day = $this->request->post('day',0);
- if(!$unionid){
- return $this->error('请上传uninid');
- }
- $userInfo = \app\model\User::where(['unionid'=>$unionid])->find();
- if(!$userInfo){
- return $this->error('未查询到此用户信息');
- }
- if($type == 'addCoin'){
- $balanceRes = \app\model\User::where(['id'=>$userInfo['id']])->inc('coin',$coin)->update();
- if(!$balanceRes){
- return $this->error('增加金币失败');
- }
- BillServiceFacade::record(1,$coin,'pay_member','通过接口充值点数',$userInfo['id'],$_GPC['uniacid']);
- }elseif($type == 'addVip'){
- if($userInfo['vip_time'] < time()){
- $balance = strtotime("+".$day."days");
- }else{
- // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
- $balance = $userInfo['vip_time'] + $day*24*60*60;
- }
- $balanceRes = \app\model\User::where('id', '=', $userInfo['id'])->update(['vip_time' => $balance]);
- BillServiceFacade::record(1,$day,'pay_member','通过接口充值时长',$userInfo['id'],$_GPC['uniacid']);
- }
- return $this->success('成功', $balanceRes);
- }
- }
|