1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php namespace App\Http\Controllers\Api\Riddle;
- use App\Http\Controllers\Api\Api;
- use App\Models\Riddle\Active;
- use App\Models\Riddle\ActiveShare as Model;
- /**
- * 活动分享记录
- *
- * @author 刘相欣
- *
- * */
- class ActiveShare extends Api{
- /**
- * 获取题目 /api/riddle_active_share/add
- *
- * */
- public function add(Model $Model,Active $Active){
- // 接口验签
- // $this->verify_sign();
- // 检查登录
- $uid = $this->checkLogin();
- // 获取参数
- $activeId = request('active_id',0);
- // 获取客户城市的数据
- $data = $Active->getOne($activeId);
- // 如果存在的话
- if( !$data ) return json_send(['code'=>'error','msg'=>'活动已下线或不存在','data'=>'']);
- // 查询条件
- $map = [];
- // 判断周期
- if( !empty($data['freq']) ) {
- if( $data['freq'] == 1 ) $map = [['insert_time','>=',now()->startOfDay()->getTimestamp()],['insert_time','<=',now()->endOfDay()->getTimestamp()]];
- if( $data['freq'] == 2 ) $map = [['insert_time','>=',now()->startOfWeek()->getTimestamp()],['insert_time','<=',now()->endOfWeek()->getTimestamp()]];
- if( $data['freq'] == 3 ) $map = [['insert_time','>=',now()->startOfMonth()->getTimestamp()],['insert_time','<=',now()->endOfMonth()->getTimestamp()]];
- }
- // 获取已分享次数
- $shareTotal = $Model->query()->where([['active_id','=',$activeId],['custom_uid','=',$uid]])->where($map)->count();
- // 计算剩余分享次数
- $data['share_last'] = ($data['join_share'] - $shareTotal <= 0 ? 0 : $data['join_share'] - $shareTotal);
- // 如果次数不够
- if( $data['share_last'] <= 0 ) return json_send(['code'=>'error','msg'=>'您已经没有分享次数了','data'=>'']);
- // 记录分享
- $id = $Model->add(['active_id'=>$activeId,'custom_uid'=>$uid]);
- // 分享成功
- if( !$id ) return json_send(['code'=>'error','msg'=>'记录失败','data'=>'']);
- // 返回结果
- return json_send(['code'=>'success','msg'=>'记录成功','data'=>['id'=>$id]]);
- }
-
- }
|