Browse Source

【Add】拉新抽奖

liuxiangxin 2 tháng trước cách đây
mục cha
commit
270ae7c91d
28 tập tin đã thay đổi với 1974 bổ sung130 xóa
  1. 214 0
      app/Http/Controllers/Admin/LotteryRecruitment.php
  2. 167 0
      app/Http/Controllers/Admin/LotteryRecruitmentRecord.php
  3. 208 0
      app/Http/Controllers/Admin/LotteryRecruitmentReward.php
  4. 1 54
      app/Http/Controllers/Admin/LotteryRiddle.php
  5. 0 53
      app/Http/Controllers/Admin/RiddleActive.php
  6. 1 1
      app/Http/Controllers/Api/Lottery/Order.php
  7. 259 0
      app/Http/Controllers/Api/Lottery/Recruitment.php
  8. 110 0
      app/Http/Controllers/Api/Lottery/RecruitmentRecord.php
  9. 1 1
      app/Http/Controllers/Api/Lottery/Riddle.php
  10. 52 0
      app/Http/Requests/Admin/Recruitment/Active.php
  11. 2 2
      app/Http/Requests/Admin/Riddle/Active.php
  12. 144 0
      app/Models/Lottery/Recruitment.php
  13. 57 0
      app/Models/Lottery/RecruitmentRecord.php
  14. 159 0
      app/Models/Lottery/RecruitmentReward.php
  15. 2 2
      app/Models/Traits/Score/BuyType.php
  16. 78 0
      resources/views/admin/lottery_recruitment/add.blade.php
  17. 79 0
      resources/views/admin/lottery_recruitment/edit.blade.php
  18. 96 0
      resources/views/admin/lottery_recruitment/index.blade.php
  19. 89 0
      resources/views/admin/lottery_recruitment_record/index.blade.php
  20. 53 0
      resources/views/admin/lottery_recruitment_reward/add.blade.php
  21. 54 0
      resources/views/admin/lottery_recruitment_reward/edit.blade.php
  22. 93 0
      resources/views/admin/lottery_recruitment_reward/index.blade.php
  23. 0 3
      resources/views/admin/lottery_riddle/index.blade.php
  24. 3 3
      resources/views/admin/lottery_riddle_record/index.blade.php
  25. 7 4
      resources/views/admin/poster/index.blade.php
  26. 0 3
      resources/views/admin/riddle_active/index.blade.php
  27. 16 0
      routes/api.php
  28. 29 4
      routes/web.php

+ 214 - 0
app/Http/Controllers/Admin/LotteryRecruitment.php

@@ -0,0 +1,214 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Facades\Servers\WechatMini\Mini;
+use App\Http\Requests\Admin\Recruitment\Active as Request;
+use App\Models\Lottery\Recruitment as Model;
+use App\Models\Lottery\RecruitmentReward;
+use App\Models\City;
+use App\Models\WeiBan\Tags as WeiBanTags;
+
+/**
+ * 优惠券自动发放规则
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryRecruitment extends Auth{
+
+    protected function _initialize(){
+        parent::_initialize();
+        $this->assign('breadcrumb1','抽奖管理');
+        $this->assign('breadcrumb2','拉新抽奖');
+    }
+
+    /**
+     * 列表页
+     *
+     * */
+    public function index(Model $Model){
+        // 接收参数
+        $name					= request('name','');
+        // 查询条件
+        $map 					= [];
+        // 组合条件
+        if( $name )				$map[] = ['name','=',$name];
+        // 查询数据
+        $list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+        // 循环处理数据
+        foreach ($list as $key => $value) {
+            // 小程序链接
+            $value['mp_urllink']= $this->getUrlLink($value['id']);
+            // 重组
+            $list[$key]			= $value;
+        }
+        // 分配数据
+        $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+        $this->assign('list',$list);
+        // 加载模板
+        return 					$this->fetch();
+    }
+
+    /**
+     * 获取小程序链接
+     *
+     */
+    private function getUrlLink($id){
+        // 结果数据
+        $link                  = cache('admin:lottery:recruitment:urllink:'.$id);
+        // 不存在数据
+        if ( is_null($link) ) {
+            // 从数据库获取数据
+            $link              = Mini::getUrlLink('pages/recruitment/lottery','id='.$id);
+            // 存起来
+            cache(['admin:lottery:recruitment:urllink:'.$id=>$link],$link ? now()->addDays(28) : now()->addMinutes(3));
+        }
+        // 返回结果
+        return                  $link;
+
+    }
+
+    /**
+     * 添加
+     *
+     * */
+    public function add(Request $request,Model $Model,City $City,WeiBanTags $WeiBanTags){
+        if( request()->isMethod('post') ){
+            // 验证参数
+            $request->scene('add')->validate();
+            // 接收数据
+            $data['logo']			= request('logo','');
+            $data['name']			= request('name','');
+            $data['rule']			= request('rule','');
+            $data['freq']			= request('freq',0);
+            $data['lucky_num']		= request('lucky_num',0);
+            $data['max_reward']		= request('max_reward',0);
+            $data['start_time']		= request('start_time','');
+            $data['end_time']		= request('end_time','');
+            $data['start_time']		= $data['start_time'] ? strtotime($data['start_time']) : 0;
+            $data['end_time']		= $data['end_time'] ? strtotime($data['end_time']) : 0;
+            $cityIds				= request('city_ids',[]);
+			$tagScope				= request('tag_scope',[]);
+			$data['city_ids']		= implode(',',$cityIds);
+			$data['tag_scope']		= implode(',',$tagScope);
+			$data['status']			= 1;
+            // 写入数据表
+            $id						= $Model->add($data);
+            // 如果操作失败
+            if( !$id ) 				return json_send(['code'=>'error','msg'=>'新增失败']);
+            // 记录行为
+            $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
+            // 告知结果
+            return					json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
+        }
+        // 获取列表
+		$cityList					= $City->getCityList();
+		// 标签列表
+		$tagData					= $WeiBanTags->query()->groupBy('group')->groupBy('name')->get(['group','name'])->toArray();
+		// 标签列表
+		$tagList					= [];
+		// 循环数据
+		foreach ($tagData as $value) {
+			$tagList[$value['group']][] = $value['name'];
+		}
+		// 分配数据
+		$this->assign('cityList',$cityList);
+		$this->assign('tagList',$tagList);
+        // 分配数据
+        $this->assign('crumbs','新增');
+        // 加载模板
+        return						$this->fetch();
+    }
+
+    /**
+     * 修改
+     *
+     * */
+    public function edit(Request $request,Model $Model,City $City,WeiBanTags $WeiBanTags){
+        // 接收参数
+        $id							= request('id',0);
+        // 查询用户
+        $oldData					= $Model->where(['id'=>$id])->first();
+        // 修改
+        if(request()->isMethod('post')){
+            // 验证参数
+            $request->scene('edit')->validate();
+            // 接收数据
+            $data['logo']			= request('logo','');
+            $data['name']			= request('name','');
+            $data['rule']			= request('rule','');
+            $data['freq']			= request('freq',0);
+            $data['lucky_num']		= request('lucky_num',0);
+            $data['max_reward']		= request('max_reward',0);
+            $data['start_time']		= request('start_time','');
+            $data['end_time']		= request('end_time','');
+            $data['start_time']		= $data['start_time'] ? strtotime($data['start_time']) : 0;
+            $data['end_time']		= $data['end_time'] ? strtotime($data['end_time']) : 0;
+            $cityIds				= request('city_ids',[]);
+			$tagScope				= request('tag_scope',[]);
+			$data['city_ids']		= implode(',',$cityIds);
+			$data['tag_scope']		= implode(',',$tagScope);
+            // 写入数据表
+            $result					= $Model->edit($id,$data);
+            // 如果操作失败
+            if( !$result ) 			return json_send(['code'=>'error','msg'=>'修改失败']);
+            // 记录行为
+            $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
+            // 告知结果
+            return					json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
+        }
+        // 错误告知
+		if( !$oldData )				return $this->error('查无数据');
+		// 获取城市ID
+		$oldData['city_ids']		= explode(',',$oldData['city_ids']);
+		$oldData['tag_scope']		= explode(',',$oldData['tag_scope']);
+		// 获取列表
+		$cityList					= $City->getCityList();
+		// 标签列表
+		$tagData					= $WeiBanTags->query()->groupBy('group')->groupBy('name')->get(['group','name'])->toArray();
+		// 标签列表
+		$tagList					= [];
+		// 循环数据
+		foreach ($tagData as $value) {
+			$tagList[$value['group']][] = $value['name'];
+		}
+		// 分配数据
+		$this->assign('cityList',$cityList);
+		$this->assign('tagList',$tagList);
+        $this->assign('oldData',$oldData);
+        $this->assign('crumbs','修改');
+        // 加载模板
+        return						$this->fetch();
+    }
+
+    /**
+     * 修改状态
+     *
+     * */
+    public function set_status(Request $request,Model $Model,RecruitmentReward $RecruitmentReward){
+        // 验证参数
+        $request->scene('set_status')->validate();
+        // 设置状态
+        $id				= request('id',0);
+        $status			= request('status',0);
+        // 查询用户
+        $oldData		= $Model->where(['id'=>$id])->first();
+        // 如果用户不存在
+        if( !$oldData )	return json_send(['code'=>'error','msg'=>'数据不存在']);
+        // 如果设置上架
+        if( !$status )	{
+            // 判断奖品个数
+            $count		= $RecruitmentReward->query()->where([['lottery_id','=',$id]])->count();
+            // 获取统计数量
+            if( $count < 3 || $count > 7 ) return json_send(['code'=>'error','msg'=>'奖项请设置3~7个再启用']);
+        }
+        // 执行修改
+        $result			= $Model->edit($id,['status'=>$status]);
+        // 提示新增失败
+        if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
+        // 记录行为
+        $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
+        // 告知结果
+        return 			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
+    }
+
+}

+ 167 - 0
app/Http/Controllers/Admin/LotteryRecruitmentRecord.php

@@ -0,0 +1,167 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\Lottery\OrderReward as Request;
+use App\Models\Custom;
+use App\Models\Lottery\RecruitmentRecord as Model;
+use App\Models\Lottery\Recruitment as LotteryRecruitment;
+/**
+ * 抽奖记录
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryRecruitmentRecord extends Auth{
+
+    protected function _initialize(){
+        parent::_initialize();
+        $this->assign('breadcrumb1','下单抽奖');
+        $this->assign('breadcrumb2','抽奖记录');
+    }
+
+    /**
+     * 列表页
+     *
+     * */
+    public function index(Model $Model,LotteryRecruitment $LotteryRecruitment,Custom $Custom){
+        // 接受参数
+        $lotteryId				= request('lottery_id',0);
+        $customCode				= request('custom_code','');
+        $startTime				= request('start_time','');
+        $endTime				= request('end_time','');
+        $status					= request('status');
+        // 查询条件
+        $map 					= [['lottery_recruitment_record.reward_id','>',0]];
+        // 编码转ID
+        $customUid				= $customCode ? $Custom->codeToId($customCode) : 0;
+        if( $customUid )		$map[] = ['lottery_recruitment_record.custom_uid','=',$customUid];
+        if( $lotteryId )		$map[] = ['lottery_recruitment_record.lottery_id','=',$lotteryId];
+        if( $startTime )		$map[] = ['lottery_recruitment_record.insert_time','>=',strtotime($startTime)];
+        if( $endTime )			$map[] = ['lottery_recruitment_record.insert_time','<=',strtotime($endTime)];
+        if( !is_null($status) )	$map[] = ['lottery_recruitment_record.status','=',$status];
+        // 查询数据
+        $list					= $Model->query()
+                                    ->join('lottery_recruitment','lottery_recruitment.id','=','lottery_recruitment_record.lottery_id')
+                                    ->join('custom','custom.uid','=','lottery_recruitment_record.custom_uid')
+                                    ->where($map)
+                                    ->select(['lottery_recruitment_record.*','custom.weiban_extid','custom.username','lottery_Recruitment.name as active_name'])
+                                    ->orderByDesc('id')
+                                    ->paginate(config('page_num',10));
+        // 循环处理数据
+        foreach ($list as $key => $value) {
+            // 组合数据
+            $value['state']		= $Model->getRecordState($value['status'],'name');
+            // id转编号
+            $value['custom_code'] = $Custom->idToCode($value['custom_uid']);
+            // 重组
+            $list[$key]			= $value;
+        }
+        // 获取列表
+        $statusList 			= $Model->getRecordStateList();
+        // 获取列表
+        $lotteryList 			= $LotteryRecruitment->query()->get(['id','name'])->toArray();
+        // 分配数据
+        $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+        $this->assign('list',$list);
+        $this->assign('statusList',$statusList);
+        $this->assign('lotteryList',$lotteryList);
+        // 加载模板
+        return 					$this->fetch();
+    }
+
+
+    /**
+     * 修改状态
+     *
+     * */
+    public function set_status(Request $request,Model $Model){
+        // 验证参数
+        $request->scene('set_status')->validate();
+        // 设置状态
+        $id				= request('id',0);
+        $status			= request('status',0);
+        // 查询用户
+        $oldData		= $Model->where(['id'=>$id])->first();
+        // 如果用户不存在
+        if( !$oldData )	return json_send(['code'=>'error','msg'=>'数据不存在']);
+        // 执行修改
+        $result			= $Model->edit($id,['status'=>$status]);
+        // 提示新增失败
+        if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
+        // 记录行为
+        $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
+        // 告知结果
+        return 			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
+    }
+
+    /**
+	 * 导出表格
+	 * 
+	 * */
+	public function down_excel(Model $Model,Custom $Custom){
+		// 接受参数
+        $lotteryId				= request('lottery_id',0);
+        $customCode				= request('custom_code','');
+        $startTime				= request('start_time','');
+        $endTime				= request('end_time','');
+        $status					= request('status');
+        // 查询条件
+        $map 					= [['lottery_recruitment_record.reward_id','>',0]];
+        // 编码转ID
+        $customUid				= $customCode ? $Custom->codeToId($customCode) : 0;
+        if( $customUid )		$map[] = ['lottery_recruitment_record.custom_uid','=',$customUid];
+        if( $lotteryId )		$map[] = ['lottery_recruitment_record.lottery_id','=',$lotteryId];
+        if( $startTime )		$map[] = ['lottery_recruitment_record.insert_time','>=',strtotime($startTime)];
+        if( $endTime )			$map[] = ['lottery_recruitment_record.insert_time','<=',strtotime($endTime)];
+        if( !is_null($status) )	$map[] = ['lottery_recruitment_record.status','=',$status];
+        // 查询数据
+        $list					= $Model->query()
+                                    ->join('lottery_Recruitment','lottery_Recruitment.id','=','lottery_recruitment_record.lottery_id')
+                                    ->join('custom','custom.uid','=','lottery_recruitment_record.custom_uid')
+                                    ->where($map)
+                                    ->select([
+                                        'lottery_recruitment_record.id',
+                                        'lottery_Recruitment.id as active_id',
+                                        'lottery_Recruitment.name as active_name',
+                                        'custom.uid as custom_uid',
+                                        'custom.username',
+                                        'lottery_recruitment_record.reward_name',
+                                        'lottery_recruitment_record.status',
+                                        'lottery_recruitment_record.insert_time',
+                                        'custom.weiban_extid',
+                                    ])
+                                    ->orderByDesc('id')->get()->toArray();
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+            // 组合数据
+            $value['status']	    = $Model->getRecordState($value['status'],'name');
+			$value['custom_uid']    = $Custom->idToCode($value['custom_uid']);
+			$value['username'] 	    = hide_phone($value['username']);
+			$value['insert_time']   = date('Y-m-d H:i:s',$value['insert_time']);
+			// 重组
+			$list[$key]			    = $value;
+		}
+		// 去下载
+		$this->toDown($list);
+	}
+
+	/**
+	 * 去下载
+	 */
+	private function  toDown($data){
+		// xlsx文件保存路径
+		$excel      		= new \Vtiful\Kernel\Excel(['path' =>public_path().'/uploads/']);
+		$filePath 			= $excel->fileName(uniqid().'.xlsx', 'sheet1')->header(['记录ID','活动ID','活动名称','客户编码','客户昵称','奖品名称','中奖状态','中奖时间','微伴ID'])->data($data)->output();
+		header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+		header('Content-Disposition: attachment;filename="灯谜抽奖中奖记录'.date('Y-m-d His').'.xlsx"');
+		header('Content-Length: ' . filesize($filePath));
+		header('Content-Transfer-Encoding: binary');
+		header('Cache-Control: must-revalidate');
+		header('Cache-Control: max-age=0');
+		header('Pragma: public');
+		ob_clean();
+		flush();
+		// 输出文件,成功删除文件路径
+		if ( copy($filePath, 'php://output') )  @unlink($filePath);
+	}
+
+}

+ 208 - 0
app/Http/Controllers/Admin/LotteryRecruitmentReward.php

@@ -0,0 +1,208 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\Lottery\OrderReward as Request;
+use App\Models\Coupon;
+use App\Models\Lottery\RecruitmentReward as Model;
+use App\Models\Lottery\Recruitment as LotteryRecruitment;
+/**
+ * 抽奖奖品
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryRecruitmentReward extends Auth{
+	
+	protected function _initialize(){
+		parent::_initialize();
+		$this->assign('breadcrumb1','下单抽奖');
+		$this->assign('breadcrumb2','抽奖奖品');
+	}
+
+	/**
+	 * 列表页
+	 * 
+	 * */
+    public function index(Model $Model,LotteryRecruitment $LotteryRecruitment){
+		// 接收参数
+		$lotteryId				= request('lottery_id',0);
+		$name					= request('name','');
+		// 查询条件
+		$map 					= [];
+		// 组合条件
+		if( $lotteryId )		$map[] = ['lottery_id','=',$lotteryId];
+		if( $name )				$map[] = ['reward_name','=',$name];
+		// 查询数据
+		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// 获取类型名称
+			$value['reward_type'] = $Model->getRewardType($value['reward_type'],'name');
+			// 重组
+			$list[$key]			= $value;
+		}
+		// 获取列表
+		$lotteryList 			= $LotteryRecruitment->query()->get(['id','name'])->toArray();
+		// 分配数据
+		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+		$this->assign('list',$list);
+		$this->assign('lotteryList',$lotteryList);
+		// 加载模板
+		return 					$this->fetch();
+    }
+
+	/**
+	 * 添加
+	 * 
+	 * */
+	public function add(Request $request,Model $Model,LotteryRecruitment $LotteryRecruitment,Coupon $Coupon){
+		if( request()->isMethod('post') ){
+			// 验证参数
+			$request->scene('add')->validate();
+			// 接收数据
+			$data['reward_name']	= request('reward_name','');
+			$data['reward_thumb']	= request('reward_thumb','');
+			$data['reward_type']	= request('reward_type',0);
+			$data['reward_total']	= request('reward_total',0);
+			$data['reward_info']	= request('reward_info','');
+			$data['probability']	= request('probability',0);
+			$data['lottery_id']		= request('lottery_id',0);
+			$data['status']			= 1;
+			// 计算统计数量
+			$count					= $Model->query()->where([['lottery_id','=',$data['lottery_id']]])->count();
+			// 获取统计数量
+			if( $count >= 7 )		return json_send(['code'=>'error','msg'=>'奖项不可超过7个']);
+			// 如果是积分,转整数
+			if( $data['reward_type'] == 1 )  {
+				// 
+				$data['reward_info'] = intval($data['reward_info']);
+				// 如果操作失败
+				if( !$data['reward_info']  ) return json_send(['code'=>'error','msg'=>'请填写积分信息']);
+			}
+			// 如果是优惠券
+			if( $data['reward_type'] == 2 )  {
+				// 优惠券信息
+				$data['reward_info'] = $Coupon->codeToId($data['reward_info']);
+				// 如果操作失败
+				if( !$data['reward_info']  ) return json_send(['code'=>'error','msg'=>'请填写正确的优惠券编码']);
+			}
+			// 如果是红包
+			if( $data['reward_type'] == 3 )  $data['reward_info'] = number_format(floatval($data['reward_info']),2,'.','');
+			// 写入数据表
+			$id						= $Model->add($data);
+			// 如果操作失败
+			if( !$id ) 				return json_send(['code'=>'error','msg'=>'新增失败']);
+			// 记录行为
+			$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
+			// 告知结果
+			return					json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
+		}
+		// 抽奖活动ID
+		$lotteryId					= request('lottery_id',0);
+		// 通过抽奖活动ID获取已经存在的概率
+		$maxProbability				= 100 - (int) $Model->query()->where([['lottery_id','=',$lotteryId]])->sum('probability');
+		// 获取列表
+		$lotteryList 				= $LotteryRecruitment->query()->get(['id','name'])->toArray();
+		// 奖品类型
+		$typeList					= $Model->getRewardTypeList();
+		// 分配数据
+		$this->assign('crumbs','新增');
+		$this->assign('typeList',$typeList);
+		$this->assign('lotteryList',$lotteryList);
+		$this->assign('maxProbability',$maxProbability);
+		// 加载模板
+		return						$this->fetch(); 
+	}
+
+	/**
+	 * 修改
+	 * 
+	 * */
+	public function edit(Request $request,Model $Model,LotteryRecruitment $LotteryRecruitment,Coupon $Coupon){
+		// 接收参数
+		$id							= request('id',0);
+		// 查询用户
+		$oldData					= $Model->where(['id'=>$id])->first();
+		// 修改
+		if(request()->isMethod('post')){
+			// 验证参数
+			$request->scene('edit')->validate();
+			// 接收数据
+			$data['reward_name']	= request('reward_name','');
+			$data['reward_thumb']	= request('reward_thumb','');
+			$data['reward_type']	= request('reward_type',0);
+			$data['reward_total']	= request('reward_total',0);
+			$data['reward_info']	= request('reward_info','');
+			$data['probability']	= request('probability',0);
+			$data['lottery_id']		= request('lottery_id',0);
+			// 计算统计数量
+			$count					= $Model->query()->where([['lottery_id','=',$data['lottery_id']],['id','<>',$id]])->count();
+			// 获取统计数量
+			if( $count >= 7 )		return json_send(['code'=>'error','msg'=>'奖项不可超过7个']);
+			// 如果是积分,转整数
+			if( $data['reward_type'] == 1 )  {
+				// 
+				$data['reward_info'] = intval($data['reward_info']);
+				// 如果操作失败
+				if( !$data['reward_info']  ) return json_send(['code'=>'error','msg'=>'请填写积分信息']);
+			}
+			// 如果是优惠券
+			if( $data['reward_type'] == 2 )  {
+				// 优惠券信息
+				$data['reward_info'] = $Coupon->codeToId($data['reward_info']);
+				// 如果操作失败
+				if( !$data['reward_info']  ) return json_send(['code'=>'error','msg'=>'请填写正确的优惠券编码']);
+			}
+			// 如果是红包
+			if( $data['reward_type'] == 3 )  $data['reward_info'] = number_format(floatval($data['reward_info']),2,'.','');
+			// 写入数据表
+			$result					= $Model->edit($id,$data);
+			// 如果操作失败
+			if( !$result ) 			return json_send(['code'=>'error','msg'=>'修改失败']);
+			// 记录行为
+			$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
+			// 告知结果
+			return					json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
+		}
+		// 错误告知
+		if( !$oldData )				return $this->error('查无数据');
+		// 通过抽奖活动ID获取已经存在的概率
+		$maxProbability				= 100 - ((int) $Model->query()->where([['lottery_id','=',$oldData['lottery_id']]])->sum('probability')) + $oldData['probability'];
+		// 获取列表
+		$lotteryList 				= $LotteryRecruitment->query()->get(['id','name'])->toArray();
+		// 奖品类型
+		$typeList					= $Model->getRewardTypeList();
+		// 数据分配
+		$this->assign('crumbs','修改');
+		$this->assign('oldData',$oldData);
+		$this->assign('typeList',$typeList);
+		$this->assign('lotteryList',$lotteryList);
+		$this->assign('maxProbability',$maxProbability);
+		// 加载模板
+		return						$this->fetch();
+	}
+
+	/**
+	 * 修改状态
+	 * 
+	 * */
+	public function set_status(Request $request,Model $Model){
+		// 验证参数
+		$request->scene('set_status')->validate();
+		// 设置状态
+		$id				= request('id',0);
+		$status			= request('status',0);
+		// 查询用户
+		$oldData		= $Model->where(['id'=>$id])->first();
+		// 如果用户不存在
+		if( !$oldData )	return json_send(['code'=>'error','msg'=>'数据不存在']);
+		// 执行修改
+		$result			= $Model->edit($id,['status'=>$status]);
+		// 提示新增失败
+		if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
+		// 记录行为
+		$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
+		// 告知结果
+		return 			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
+	}
+
+}

+ 1 - 54
app/Http/Controllers/Admin/LotteryRiddle.php

@@ -1,12 +1,11 @@
 <?php namespace App\Http\Controllers\Admin;
 
 use App\Facades\Servers\WechatMini\Mini;
-use App\Http\Requests\Admin\Lottery\Order as Request;
+use App\Http\Requests\Admin\Riddle\Active as Request;
 use App\Models\Lottery\Riddle as Model;
 use App\Models\City;
 use App\Models\Lottery\RiddleReward;
 use App\Models\WeiBan\Tags as WeiBanTags;
-use Illuminate\Support\Facades\DB;
 use Intervention\Image\Facades\Image;
 
 /**
@@ -69,58 +68,6 @@ class LotteryRiddle extends Auth{
 
     }
 
-    /**
-     * 获取小程序海报
-     *
-     */
-    public function get_poster(Model $Model){
-        // 接收参数
-        $id								= request('id',0);
-        // 查询用户
-        $oldData						= $Model->where(['id'=>$id])->first();
-        // 错误告知
-        if( !$oldData )					return $this->error('查无数据');
-        // 获取分享海报图片
-        $result 						= $this->getShareImage('id='.$id);
-        // 错误提示
-        if( isset($result['error']) )	return $this->error($result['error']);
-        // 分配数据
-        $this->assign('image',$result);
-        $this->assign('oldData',$oldData);
-        $this->assign('crumbs','海报');
-        // 加载模板
-        return 							$this->fetch();
-    }
-
-    /**
-     * 获取分享海报图片
-     * @param  int $scene  场景值
-     *
-     */
-    private function getShareImage($scene){
-        // 尝试执行
-        try {
-            // 加载图片
-            $image							= Image::make(public_path('uploads/images/poster/').'score_reward.png');
-            // 生成小程序二维码
-            $qrcode							= Mini::getUnlimit($scene,['page'=>'pages/orders/lottery','width'=>280,'is_hyaline'=>true]);
-            // 错误提示
-            if( isset($qrcode['error']) )	return $qrcode;
-            // 加载图片
-            $qrcode							= Image::make($qrcode)->resize(200,200);
-            // 插入图片
-            $image->insert($qrcode,'bottom-left',60,60);
-            // 转码成字符串
-            $image							= $image->encode('jpg', 90)->__toString();
-            // 转base64
-            $base64							= 'data:image/jpg;base64,' . base64_encode($image);
-            // 返回结果
-            return							$base64;
-        } catch (\Throwable $th) {
-            // 错误提示
-            return 							['error'=>$th->getMessage()];
-        }
-    }
 
     /**
      * 添加

+ 0 - 53
app/Http/Controllers/Admin/RiddleActive.php

@@ -67,59 +67,6 @@ class RiddleActive extends Auth{
 
 	}
 
-	/**
-	 * 获取小程序海报
-	 * 
-	 */
-	public function get_poster(Model $Model){
-		// 接收参数
-		$id								= request('id',0);
-		// 查询用户
-		$oldData						= $Model->where(['id'=>$id])->first();
-		// 错误告知
-		if( !$oldData )					return $this->error('查无数据');
-		// 获取分享海报图片
-		$result 						= $this->getShareImage('id='.$id);
-		// 错误提示
-		if( isset($result['error']) )	return $this->error($result['error']);
-		// 分配数据
-		$this->assign('image',$result);
-		$this->assign('oldData',$oldData);
-		$this->assign('crumbs','海报');
-		// 加载模板
-		return 							$this->fetch();
-	}
-
-	/**
-	 * 获取分享海报图片
-	 * @param  int $scene  场景值
-	 * 
-	 */
-	private function getShareImage($scene){
-		// 尝试执行
-		try {
-			// 加载图片
-			$image							= Image::make(public_path('uploads/images/poster/').'score_reward.png');
-			// 生成小程序二维码
-			$qrcode							= Mini::getUnlimit($scene,['page'=>'pages/activity/index','width'=>280,'is_hyaline'=>true]);
-			// 错误提示
-			if( isset($qrcode['error']) )	return $qrcode;
-			// 加载图片
-			$qrcode							= Image::make($qrcode)->resize(200,200);
-			// 插入图片
-			$image->insert($qrcode,'bottom-left',60,60);
-			// 转码成字符串
-			$image							= $image->encode('jpg', 90)->__toString();
-			// 转base64
-			$base64							= 'data:image/jpg;base64,' . base64_encode($image);
-			// 返回结果
-			return							$base64;
-		} catch (\Throwable $th) {
-			// 错误提示
-			return 							['error'=>$th->getMessage()];
-		}
-	}
-
 	/**
 	 * 添加
 	 * 

+ 1 - 1
app/Http/Controllers/Api/Lottery/Order.php

@@ -201,7 +201,7 @@ class Order extends Api{
 						// 积分大于0
 						if( $rewardResult['reward_info'] > 0 ){
 							// 积分发放
-							$result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,2);
+							$result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,3);
 							// 发放失败,改为未中奖
 							if( isset($result['error']) ) $rewardIndex = 0;
 							// 发放成功,状态为已完成

+ 259 - 0
app/Http/Controllers/Api/Lottery/Recruitment.php

@@ -0,0 +1,259 @@
+<?php namespace App\Http\Controllers\Api\Lottery;
+
+use App\Http\Controllers\Api\Api;
+use App\Models\Lottery\Recruitment as Model;
+use App\Models\Lottery\RecruitmentUsable;
+use App\Models\Custom;
+use App\Models\CustomCoupon;
+use App\Models\CustomScore;
+use App\Models\CustomAmount;
+use App\Models\Lottery\RecruitmentRecord;
+use App\Models\Lottery\RecruitmentReward as RecruitmentReward;
+use Illuminate\Support\Facades\DB;
+use App\Models\WeiBan\Tags as WeiBanTags;
+
+/**
+ * 积分抽奖
+ * 
+ * @author 刘相欣
+ * 
+ * */
+class Recruitment extends Api{
+
+	/**
+	 * 获取抽奖配置		/api/lottery_recruitment/get_detail
+	 * 
+	 * 
+	 * */
+	public function get_detail(Model $Model,Custom $Custom,RecruitmentReward $RecruitmentReward,RecruitmentUsable $RecruitmentUsable,WeiBanTags $WeiBanTags){
+		// 接口验签
+		// $this->verify_sign();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 获取客户信息
+		$custom							= $Custom->getOne($uid);
+		// 如果存在的话
+		if( !$custom )					return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
+		// 接收参数
+		$id 							= request('id',0);
+		// 获取活动
+		$data			                = $Model->getOne($id);
+		// 如果存在的话
+		if( !$data )					return json_send(['code'=>'error','msg'=>'暂无活动','data'=>$data]);
+		// 默认可以参加活动
+		$data['allow_join']				= 1;
+		// 判断是不是可以参与
+		if( $data['tag_scope'] )		{
+			// 解析数组
+			$data['tag_scope']			= explode(',',$data['tag_scope']);
+			// 查询用户标签
+			$tags						= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
+			// 标签范围限定时,默认不能参与
+			$data['allow_join'] 		= 0;
+			// 判断标签是不是存在
+			foreach ($tags as $value) 	{
+				// 标签范围内,允许参加
+				if( in_array($value['name'],$data['tag_scope']) )  $data['allow_join'] = 1;
+			}
+			// 如果不能参与
+			if( !$data['allow_join'] )	return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
+		}
+		// 判断是不是可以参与
+		if( $data['city_ids'] )			{
+			// 解析数组
+			$data['city_ids']			= explode(',',$data['city_ids']);
+			// 如果不在城市范围
+			if( !in_array($custom['city_id'],$data['city_ids']) ) $data['allow_join'] = 0;
+			// 如果不能参与
+			if( !$data['allow_join'] )	return json_send(['code'=>'error','msg'=>'账号不在活动城市','data'=>['error'=>'账号不在活动城市']]);
+		}
+		// 奖品
+		$reward 						= $RecruitmentReward->getListByLottery($data['id']);
+		// 活动暂无奖品
+		if( !$reward )					return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
+		// logo
+		$data['logo']					= $data['logo'] ? path_compat($data['logo']) : '';
+		// 通过活动ID,查询奖品
+		$data['reward_list']			= [];
+		// 奖品数据
+		foreach ($reward as $value) 	{
+			// 奖项
+			$data['reward_list'][]		= ['id'=>$value['id'],'name'=>$value['reward_name'],'img'=>$value['reward_thumb'],'reward_type'=>$value['reward_type']];
+		}
+		// 查询用户可用抽奖次数
+        $number							= $RecruitmentUsable->query()->where([['custom_uid','=',$uid],['lottery_id','=',$id]])->value('number');
+		// 最少为0,避免显示异常
+		$data['number']				    = $number < 0 ? 0 : $number;
+		// 时间处理
+		$data['start_date']				= date('Y/m/d H:i',$data['start_time']);
+		// 时间处理
+		$data['end_date']				= date('Y/m/d H:i',$data['end_time']);
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+	}
+
+	/**
+	 * 抽奖								/api/lottery_recruitment/get_reward
+	 * 
+	 * */
+	public function get_reward(Model $Model,Custom $Custom,RecruitmentRecord $RecruitmentRecord,RecruitmentReward $RecruitmentReward,CustomCoupon $CustomCoupon,CustomScore $CustomScore,CustomAmount $CustomAmount,WeiBanTags $WeiBanTags){
+		// 接口验签
+		// $this->verify_sign();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 获取活动
+		$lotteryId						= request('lottery_id',0);
+		// 如果存在的话
+		if( !$lotteryId )				return json_send(['code'=>'error','msg'=>'请选择参与的活动','data'=>['error'=>"抽奖活动ID有误"]]);
+		// 获取客户信息
+		$custom							= $Custom->getOne($uid);
+		// 如果存在的话
+		if( !$custom )					return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
+		// 通过活动ID,查询奖品
+		$data							= $Model->getOne($lotteryId);
+		// 如果存在的话
+		if( !$data )					return json_send(['code'=>'error','msg'=>'活动不存在或未开始','data'=>$data]);
+		// 活动时间判断
+		if( $data['start_time'] > time() ) return json_send(['code'=>'error','msg'=>'活动暂未开始','data'=>$data]);
+		// 活动时间判断
+		if( $data['end_time'] < time() ) return json_send(['code'=>'error','msg'=>'活动已结束','data'=>$data]);
+		// 默认可以参加活动
+		$data['allow_join']				= 1;
+		// 判断是不是可以参与
+		if( $data['tag_scope'] )		{
+			// 解析数组
+			$data['tag_scope']			= explode(',',$data['tag_scope']);
+			// 查询用户标签
+			$tags						= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
+			// 标签范围限定时,默认不能参与
+			$data['allow_join'] 		= 0;
+			// 判断标签是不是存在
+			foreach ($tags as $value) 	{
+				// 标签范围内,允许参加
+				if( in_array($value['name'],$data['tag_scope']) )  $data['allow_join'] = 1;
+			}
+			// 如果不能参与
+			if( !$data['allow_join'] )	return json_send(['code'=>'error','msg'=>'不符合参与条件','data'=>['error'=>'不符合参与条件']]);
+		}
+		// 判断是不是可以参与
+		if( $data['city_ids'] )			{
+			// 解析数组
+			$data['city_ids']			= explode(',',$data['city_ids']);
+			// 如果不在城市范围
+			if( !in_array($custom['city_id'],$data['city_ids']) ) $data['allow_join'] = 0;
+			// 如果不能参与
+			if( !$data['allow_join'] )	return json_send(['code'=>'error','msg'=>'账号不在活动城市','data'=>['error'=>'账号不在活动城市']]);
+		}
+		// 奖品
+		$reward 						= $RecruitmentReward->getListByLottery($data['id']);
+		// 活动暂无奖品
+		if( !$reward )					return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
+        // 查询用户已参与次数
+        $data['join_num']				= (int)$RecruitmentRecord->query()->where([['custom_uid','=',$uid],['lottery_id','=',$lotteryId]])->count();
+        // 计算剩余次数
+        $data['join_num']				= $data['lucky_num'] - $data['join_num'];
+		// 如果次数不够
+		if( $data['join_num'] <= 0 )	return json_send(['code'=>'error','msg'=>'抽奖次数已用完','data'=>['error'=>'抽奖次数已用完']]);
+		// 抽奖记录
+		$record							= ['custom_uid'=>$uid,'lottery_id'=>$lotteryId,'reward_id'=>0,'reward_name'=>0,'status'=>1];
+		// 开启事务
+		DB::beginTransaction();
+		try{
+			// 查询条件
+			$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()]];
+			}
+			// 是否限制中奖次数字段,没有默认中奖一次
+			$data['max_reward']				= isset($data['max_reward']) ? 1 : $data['max_reward'];
+			// 限制中奖则获取中奖次数
+			$rewarTotal						= $data['max_reward'] ? $RecruitmentRecord->query()->where([['lottery_id','=',$data['id']],['custom_uid','=',$uid],['reward_id','>',0]])->where($map)->count() : 0;
+			// 中奖上限以后不再中奖
+			$rewardIndex                    = ($data['max_reward'] && $rewarTotal >= $data['max_reward']) ? 0 : $RecruitmentReward->getRewardResult($reward);
+			// 如果中奖,下标不是0
+            if( $rewardIndex )				{
+                // 获取奖品
+                $rewardResult				= $reward[$rewardIndex];
+                // 奖品记录ID
+                if( !empty($rewardResult['id']) ){
+                    // 如果是积分
+                    if( $rewardResult['reward_type'] == 1 ){
+                        // 积分大于0
+                        if( $rewardResult['reward_info'] > 0 ){
+                            // 积分发放
+                            $result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,5);
+                            // 发放失败,改为未中奖
+                            if( isset($result['error']) ) $rewardIndex = 0;
+                            // 发放成功,状态为已完成
+                            $record['status']= 8;
+                        }
+                    }
+                    // 优惠券,先进行发放
+                    if( $rewardResult['reward_type'] == 2 ){
+                        // 优惠券存在ID
+                        if( $rewardResult['reward_info'] > 0 ){
+                            // 积分给与
+                            $result 		= $CustomCoupon->giveCoupon($rewardResult['reward_info'],$uid);
+                            // 发放失败,改为未中奖
+                            if( !$result ) 	$rewardIndex = 0;
+                            // 发放成功,状态为已完成
+                            $record['status']= 8;
+                        }
+                    }
+                    // 红包
+                    if( $rewardResult['reward_type'] == 3 ){
+                        // 积分大于0
+                        if( $rewardResult['reward_info'] > 0 ){
+                            // 积分发放
+                            $result 		= $CustomAmount->trade($uid,$lotteryId,$rewardResult['reward_info'],4,1,'灯谜抽奖');
+                            // 发放失败,改为未中奖
+                            if( isset($result['error']) ) $rewardIndex = 0;
+                            // 发放成功,状态为已完成
+                            $record['status']= 8;
+                        }
+                    }
+                    // 如果是实物,要求填写地址,状态设置为0
+                    if( $rewardResult['reward_type'] == 5 ) $record['status'] = 0;
+                }
+            }
+			// 中奖记录奖品
+			if( $rewardIndex ) 				{
+				// 记录,默认状态为1,进行中
+				$record['reward_id']		= $reward[$rewardIndex]['id'];
+				$record['reward_name']		= $reward[$rewardIndex]['reward_name'];
+				// 扣减次数
+				$RecruitmentReward->edit($rewardResult['id'],['reward_total'=>DB::raw('reward_total+-1')]);
+			}
+			// 写入记录
+			$result 						= $RecruitmentRecord->add($record);
+			// 写入失败
+			if( !$result	)				{
+				// 回退数据
+				DB::rollBack();
+				// 提示
+				return						json_send(['code'=>'error','msg'=>'抽奖记录失败,请重试']);
+			}
+			// 提交事务
+			DB::commit();
+			// 通过活动ID,查询奖品
+			$rewardList						= [];
+			// 奖品数据
+			foreach ($reward as $value) 	{
+				$rewardList[]				= ['id'=>$value['id'],'name'=>$value['reward_name'],'img'=>$value['reward_thumb'],'reward_type'=>$value['reward_type']];
+			}
+			// 返回结果
+			return							json_send(['code'=>'success','msg'=>'抽奖成功','data'=>['reward_list'=>$rewardList,'reward_index'=>$rewardIndex,'join_num'=>$data['join_num']-1]]);
+			// 异常处理
+		} catch (\Throwable $th) {
+			// 回退数据
+			DB::rollBack();
+			// 下单失败提示
+			return							json_send(['code'=>'error','msg'=>'抽奖失败,请重试','data'=>['error'=>$th->getMessage().$th->getLine()]]);
+		}	
+
+	}
+	
+}

+ 110 - 0
app/Http/Controllers/Api/Lottery/RecruitmentRecord.php

@@ -0,0 +1,110 @@
+<?php namespace App\Http\Controllers\Api\Lottery;
+
+use App\Http\Controllers\Api\Api;
+use App\Models\Lottery\RecruitmentRecord as Model;
+use App\Models\Lottery\RecruitmentReward as RecruitmentReward;
+use App\Http\Requests\Api\Lottery\OrderRecord as Request;
+use App\Models\CustomAddr;
+use App\Models\Custom;
+
+/**
+ * 积分抽奖记录
+ * 
+ * @author 刘相欣
+ * 
+ * */
+class RecruitmentRecord extends Api{
+
+	/**
+	 * 获取抽奖记录		/api/lottery_recruitment_record/get_list
+	 * 
+	 * */
+	public function get_list(Request $request,Model $Model){
+		// 接口验签
+		// $this->verify_sign();
+		// 验证参数
+		$request->scene('get_list')->validate();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 接受参数
+		$lotteryId						= request('lottery_id',0);
+		// 
+		$map							= [['custom_uid','=',$uid],['lottery_id','=',$lotteryId],['reward_id','>',0]];
+		// 获取客户城市的数据
+		$list			                = $Model->query()->where($map)->orderByDesc('id')->get(['id','reward_name','contact_addr','status','insert_time'])->toArray();
+		// 处理请求
+		foreach ($list as $key => $value ) {
+			// 处理数据
+			$value['insert_time'] 		= date('m/d H:i',$value['insert_time']);
+			$value['state'] 			= $Model->getRecordState($value['status'],'name');
+			// 重组数据
+			$list[$key]					= $value;
+		}
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
+	}
+
+
+	/**
+	 * 获取抽奖配置		/api/lottery_recruitment_record/set_addr
+	 * 
+	 * */
+	public function set_addr(Request $request,Model $Model,CustomAddr $CustomAddr){
+		// 接口验签
+		// $this->verify_sign();
+		// 验证参数
+		$request->scene('set_addr')->validate();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 接受参数
+		$id								= request('id',0);
+		$addrId							= request('addr_id',0);
+		// 获取地址
+		$addr							= $CustomAddr->getOne($addrId);
+		// 如果不存在数据
+		if( !$addr )					return json_send(['code'=>'error','msg'=>'地址有误,请核对','data'=>['error'=>'没有找到对应的地址']]);
+		// 重组数据
+		$addr							= ['status'=>1,'contact_name'=>$addr['contact_name'],'contact_shop'=>$addr['contact_shop'],'contact_phone'=>$addr['contact_phone'],'contact_province'=>$addr['contact_province'],'contact_city'=>$addr['contact_city'],'contact_area'=>$addr['contact_area'],'contact_addr'=>$addr['contact_addr'],'update_time'=>time()];
+		// 组合条件
+		$map							= [['custom_uid','=',$uid],['id','=',$id]];
+		// 获取客户城市的数据
+		$result			                = $Model->query()->where($map)->update($addr);
+		// 成功
+		if( !$result )					return json_send(['code'=>'error','msg'=>'地址填写失败','data'=>['error'=>'地址填写失败']]);
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>['id'=>$id]]);
+	}
+    /**
+     * 获取所有用户抽奖记录		/api/lottery_recruitment_record/get_list_all
+     *
+     * */
+    public function get_list_all(Model $Model,RecruitmentReward $RecruitmentReward,Custom $Custom){
+        // 接口验签
+        // $this->verify_sign();
+        // 检查登录
+        //$uid							= $this->checkLogin();
+        // 接受参数
+        $lotteryId						= request('lottery_id',0);
+        if( !$lotteryId )				return json_send(['code'=>'error','msg'=>'暂无活动','data'=>'缺少活动id']);
+        $map							= [['lottery_id','=',$lotteryId],['reward_id','>',0]];
+        // 获取客户城市的数据
+        $list			                = $Model->query()
+											->where($map)
+											->orderByDesc('id')
+											->take(20)
+											->get(['id','reward_name','custom_uid','reward_id','contact_addr','status','insert_time'])
+											->toArray();
+        // 处理请求
+        foreach ($list as $key => $value ) {
+            // 处理数据
+            $value['insert_time'] 		= date('m/d H:i',$value['insert_time']);
+            $value['state'] 			= $Model->getRecordState($value['status'],'name');
+            $value['reward_info'] 		= $RecruitmentReward->query()->where('id',$value['reward_id'])->value('reward_info');
+            $value['username'] 		    = $Custom->query()->where('uid',$value['custom_uid'])->value('username');
+            // 重组数据
+            $list[$key]					= $value;
+        }
+        // 返回结果
+        return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
+    }
+}

+ 1 - 1
app/Http/Controllers/Api/Lottery/Riddle.php

@@ -138,7 +138,7 @@ class Riddle extends Api{
                         // 积分大于0
                         if( $rewardResult['reward_info'] > 0 ){
                             // 积分发放
-                            $result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,2);
+                            $result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,4);
                             // 发放失败,改为未中奖
                             if( isset($result['error']) ) $rewardIndex = 0;
                             // 发放成功,状态为已完成

+ 52 - 0
app/Http/Requests/Admin/Recruitment/Active.php

@@ -0,0 +1,52 @@
+<?php namespace App\Http\Requests\Admin\Recruitment;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 灯谜活动验证器
+ * 
+ */
+class Active extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
+            // 验证字段,验证规则,提示信息
+	        'name' 			    => 'required|unique:lottery_recruitment,name,'.request('id',0),
+	        'id'                => 'required|integer|gt:0',
+            'logo'              => 'required',
+        ];
+    }
+
+    // 场景列表
+    protected   $scenes         = [
+		'add'  		            => ['name','logo'],
+        'edit'  		        => ['id','name','logo'],
+        'set_status'  		    => ['id'],
+	];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'logo.required'     => '首图必选',
+            'name.required'     => '活动名称必填',
+            'name.required'     => '活动名称已存在',
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'   		    => 'ID格式错误',
+        ];
+    }
+    
+}

+ 2 - 2
app/Http/Requests/Admin/Riddle/Active.php

@@ -10,7 +10,7 @@ class Active extends BaseRequest
 {
     /**
      * 获取应用于请求的规则
-     *
+     * 
      * @return array
      */
     public function rules()
@@ -19,7 +19,7 @@ class Active extends BaseRequest
         return      [
             // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
             // 验证字段,验证规则,提示信息
-	        'name' 			    => 'required|unique:riddle_active,name,'.request('id',0),
+	        'name' 			    => 'required|unique:lottery_riddle,name,'.request('id',0),
 	        'id'                => 'required|integer|gt:0',
             'logo'              => 'required',
         ];

+ 144 - 0
app/Models/Lottery/Recruitment.php

@@ -0,0 +1,144 @@
+<?php namespace App\Models\Lottery;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 抽奖模型
+ * 
+ */
+class Recruitment extends Model
+{
+    use HasFactory;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_recruitment';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']				= time();
+        $data['update_time']				= time();
+        // 写入数据表
+        $id						            = $this->query()->insertGetId($data);
+        // 如果操作失败
+        if( !$id )                          return $id;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id,$data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result						        = $this->query()->where(['id'=>$id])->update($data);
+        // 如果操作失败
+        if( !$result )                      return $result;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $result;
+    }
+
+    /**
+     * 获取列表
+     * @param   Bool    $force  是否强制更新
+     * 
+     */
+    public function getList($force = false)
+    {
+        // 结果数据
+        $list                  = $force ? [] : cache('admin:lottery:recruitment:list');
+        // 不存在数据
+        if ( !$list ) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status','=',0]])->get(['id','name','logo','rule','freq','lucky_num','max_reward','status','start_time','end_time','tag_scope','city_ids']);
+            // 是否有数据
+            $data              = $data ? $data->toArray() : [];
+            // 循环处理数据
+            $list              = [];
+            // 进行更新
+            foreach ($data as $value) {
+                // 重组数据
+                $list[$value['id']] = $value;
+            }
+            // 存起来
+            cache(['admin:lottery:recruitment:list'=>$list]);
+        }
+        // 返回结果
+        return                  $list;
+    }
+
+    /**
+     * 获取配置平台对应的应用数据
+     * 
+     * @param   Array      用户ID
+     * @param   String     指定字段
+     * 
+     */
+    public function getOne($id,$field='')
+    {
+        // 获取列表数据
+        $list                   = $this->getList();
+        // 获取数据
+        $one                    = isset($list[$id]) ? $list[$id] : [];
+        // 返回值
+        return                  empty($field) ? $one : ( isset($one[$field]) ? $one[$field] : null);
+    }
+
+
+    /**
+     * 获取配置平台对应的应用数据
+     * 
+     * @param   int  $cityId 城市ID
+     * 
+     */
+    public function getOneByCity($cityId){
+        // 获取列表数据
+        $list                   = $this->getList(true);
+        // 列表数据不存在
+        if( !$list )            return [];
+        // 全国的码
+        $all                    = [];
+        // 城市的码
+        $city                   = [];
+        // 循环列表
+        foreach ($list as $key => $value) {
+            //  如果没有限制城市
+			if( empty($value['city_ids']) )	{
+                $all[]         = $value;
+                continue;
+            }
+			// 如果限制了的话,转数组
+			$value['city_ids']			= explode(',',$value['city_ids']);
+			// 判断用户的城市是否在内
+			if( in_array($cityId,$value['city_ids']) )  {
+                $city[]         = $value;
+                continue;
+            }
+			// 不在范围的删除
+			unset($list[$key]);
+        }
+        // 先获取城市的,再获取全国的
+        $one                    = $city ? array_shift($city) : array_shift($all);
+        // 判断是否存在二维码
+        return                  (array) $one;
+    }
+
+}

+ 57 - 0
app/Models/Lottery/RecruitmentRecord.php

@@ -0,0 +1,57 @@
+<?php namespace App\Models\Lottery;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use App\Models\Traits\Lottery\RewardType;
+use App\Models\Traits\Lottery\RecordState;
+/**
+ * 中奖记录模型
+ * 
+ */
+class RecruitmentRecord extends Model
+{
+    use HasFactory,RewardType,RecordState;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_recruitment_record';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']				= time();
+        $data['update_time']				= time();
+        // 写入数据表
+        $id						            = $this->query()->insertGetId($data);
+        // 如果操作失败
+        if( !$id )                          return $id;
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id,$data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result						        = $this->query()->where(['id'=>$id])->update($data);
+        // 如果操作失败
+        if( !$result )                      return $result;
+        // 返回结果
+        return                              $result;
+    }
+
+}

+ 159 - 0
app/Models/Lottery/RecruitmentReward.php

@@ -0,0 +1,159 @@
+<?php namespace App\Models\Lottery;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use App\Models\Traits\Lottery\RewardType;
+
+/**
+ * 抽奖奖品模型
+ * 
+ */
+class RecruitmentReward extends Model
+{
+    use HasFactory,RewardType;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_recruitment_reward';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']				= time();
+        $data['update_time']				= time();
+        // 写入数据表
+        $id						            = $this->query()->insertGetId($data);
+        // 如果操作失败
+        if( !$id )                          return $id;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id,$data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result						        = $this->query()->where(['id'=>$id])->update($data);
+        // 如果操作失败
+        if( !$result )                      return $result;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $result;
+    }
+
+    /**
+     * 获取列表
+     * @param   bool    $force  是否强制更新
+     * 
+     */
+    public function getList($force = false)
+    {
+        // 结果数据
+        $list                  = $force ? [] : cache('admin:lottery:recruitment:reward:list');
+        // 不存在数据
+        if ( !$list ) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status','=',0]])->get(['id','reward_name','reward_thumb','reward_type','reward_total','reward_info','probability','lottery_id']);
+            // 是否有数据
+            $data              = $data ? $data->toArray() : [];
+            // 循环处理数据
+            $list              = [];
+            // 进行更新
+            foreach ($data as $value) {
+                // 处理图片
+                $value['reward_thumb'] = $value['reward_thumb'] ? path_compat($value['reward_thumb']) : '';
+                // 重组数据
+                $list[$value['id']] = $value;
+            }
+            // 存起来
+            cache(['admin:lottery:recruitment:reward:list'=>$list]);
+        }
+        // 返回结果
+        return                  $list;
+    }
+
+    /**
+     * 获取配置平台对应的应用数据
+     * 
+     * @param   array      用户ID
+     * @param   string     指定字段
+     * 
+     */
+    public function getOne($id,$field='')
+    {
+        // 获取列表数据
+        $list                   = $this->getList();
+        // 获取数据
+        $one                    = isset($list[$id]) ? $list[$id] : [];
+        // 返回值
+        return                  empty($field) ? $one : ( isset($one[$field]) ? $one[$field] : null);
+    }
+
+    /**
+     * 获取列表
+     * @param   int    $lotteryId  抽奖活动ID
+     * 
+     */
+    public function getListByLottery($lotteryId)
+    {
+        // 结果数据
+        $data                  = $this->getList();
+        //  返回结果
+        $list                  = [];
+        // 循环处理
+        foreach ($data as $value) {
+            // 获取数据
+            if( $lotteryId == $value['lottery_id'] )  $list[] = $value;
+        }
+        // 追加一个谢谢参与
+        if( $list )            array_unshift($list,['id'=>0,'reward_name'=>'谢谢参与','reward_thumb'=>'','reward_type'=>6,'reward_total'=>1,'reward_info'=>'','probability'=>0,'lottery_id'=>$lotteryId]);
+        // 返回结果
+        return                 $list;
+    }
+
+    /**
+     * 获取抽奖结果
+     * @param   array    $reward  奖品列表
+     * 
+     */
+    public function getRewardResult($reward){
+        // 从0开始
+		$offset							= 0;
+		// 随机数,包含起始值,不含结束值
+		$randInt						= random_int($offset,10000);
+		// 中奖下标
+		$index							= 0;
+		// 循环奖品
+		foreach ($reward as $key => $value) {
+            // 概率为0 或者产品份数为0,不参与
+            if( $value['probability'] <= 0 || $value['reward_total']<= 0 )  continue;
+			// 开始数值
+			$start 						= $offset;
+			// 结束数值
+			$end						= $value['probability'] ? $start + intval($value['probability'] * 100) : 0;
+			// 重新计算开始数值
+			$offset						= $end ? $end : $offset;
+			// 区间内即抽中
+			if( $start <= $randInt && $end >= $randInt ) $index = $key;
+		}
+        // 是否中奖,以及奖项下标
+        return                          $index;
+    }
+
+}

+ 2 - 2
app/Models/Traits/Score/BuyType.php

@@ -51,9 +51,9 @@ trait BuyType
                                     ],'7'=>[
                                         'id'            =>7,
                                         // 类型名称
-                                        'name'          =>'积分抽奖',
+                                        'name'          =>'抽奖奖励',
                                         // 支付方式  方式名称
-                                        'pay_type'      =>['1'=>['id'=>1,'name'=>'抽奖消耗'],'2'=>['id'=>2,'name'=>'中奖积分']],
+                                        'pay_type'      =>['1'=>['id'=>1,'name'=>'抽奖消耗'],'2'=>['id'=>2,'name'=>'积分抽奖'],'3'=>['id'=>3,'name'=>'下单抽奖'],4=>['id'=>4,'name'=>'答题抽奖'],'5'=>['id'=>5,'name'=>'拉新抽奖']],
                                     ],'8'=>[
                                         'id'            =>8,
                                         // 类型名称

+ 78 - 0
resources/views/admin/lottery_recruitment/add.blade.php

@@ -0,0 +1,78 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+<form class="post-form" action="" method="post">
+	<div class="form-group col-sm-2">
+		<label class="control-label">活动首图 [1180*490]</label>
+		<div id="logo">
+			<a id="logo-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat('')}}" width="120" />
+			</a>
+			<input type="hidden" name="logo" value="" id="input-logo" />
+		</div>
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">活动名称</label>
+		<input class="form-control" required="required" type="text" placeholder="活动名称" name="name" maxlength="45" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">开始时间</label>
+		<input class="form-control" required="required" type="datetime-local" placeholder="开始时间"  name="start_time" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">结束时间</label>
+		<input class="form-control" required="required" type="datetime-local" placeholder="结束时间" name="end_time" value="" />
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">周期频率</label>
+		<select name="freq" class="form-control" >
+			<option value="0" >活动期间</option>
+			<option value="1" >按日</option>
+			<option value="2" >按周</option>
+			<option value="3" >按月</option>
+		</select>
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">抽奖次数</label>
+		<input class="form-control" required="required" type="number" placeholder="抽奖次数" name="lucky_num" min="1" value="1" />
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">中奖次数</label>
+		<input class="form-control" required="required" type="number" placeholder="中奖次数,0不限制" name="max_reward"  value="1" />
+	</div>
+	<div class="form-group col-sm-5">
+		<label class="control-label">活动城市</label>
+		<select name="city_ids[]" class="form-control selectpicker" data-max-options="20" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>
+			@foreach ($cityList as $group)
+			<optgroup label="{{$group['name']}}">
+				@foreach ($group['city'] as $city)
+				<option value="{{$city['id']}}" >{{$city['name']}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-5">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}" >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-12">
+		<label class="control-label">活动规则</label>
+		<textarea class="form-control" name="rule" rows="10" placeholder="请输入活动规则" ></textarea>
+	</div>
+	<div class="form-group col-sm-12">
+		@csrf
+		<input id="send" type="submit" value="提交" class="btn btn-primary btn-block" />
+	</div>
+</form>
+@endsection

+ 79 - 0
resources/views/admin/lottery_recruitment/edit.blade.php

@@ -0,0 +1,79 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+<form class="post-form" action="" method="post">
+	<div class="form-group col-sm-2">
+		<label class="control-label">活动首图 [1180*490]</label>
+		<div id="logo">
+			<a id="logo-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat($oldData['logo'])}}" width="120" />
+			</a>
+			<input type="hidden" name="logo" value="{{$oldData['logo']}}" id="input-logo" />
+		</div>
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">活动名称</label>
+		<input class="form-control" required="required" type="text" placeholder="活动名称" name="name" maxlength="45" value="{{$oldData['name']}}" />
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">开始时间</label>
+		<input class="form-control" required="required" type="datetime-local" placeholder="开始时间"  name="start_time" value="{{date('Y-m-d H:i',$oldData['start_time'])}}" />
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">结束时间</label>
+		<input class="form-control" required="required" type="datetime-local" placeholder="结束时间" name="end_time" value="{{date('Y-m-d H:i',$oldData['end_time'])}}" />
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">周期频率</label>
+		<select name="freq" class="form-control" >
+			<option value="0" @if( $oldData['freq'] == 0 ) selected @endif >活动期间</option>
+			<option value="1" @if( $oldData['freq'] == 1 ) selected @endif >按日</option>
+			<option value="2" @if( $oldData['freq'] == 2 ) selected @endif >按周</option>
+			<option value="3" @if( $oldData['freq'] == 3 ) selected @endif >按月</option>
+		</select>
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">抽奖次数</label>
+		<input class="form-control" required="required" type="number" placeholder="抽奖次数" name="lucky_num" min="1" value="{{$oldData['lucky_num']}}" />
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">中奖次数</label>
+		<input class="form-control" required="required" type="number" placeholder="中奖次数,0不限制" name="max_reward"  value="{{$oldData['max_reward']}}" />
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">活动城市</label>
+		<select name="city_ids[]" class="form-control selectpicker" data-max-options="20" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>
+			@foreach ($cityList as $group)
+			<optgroup label="{{$group['name']}}">
+				@foreach ($group['city'] as $city)
+				<option value="{{$city['id']}}"  @if(in_array($city['id'],$oldData['city_ids'])) selected @endif >{{$city['name']}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-4">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" data-max-options="10" data-live-search="true" data-live-search-placeholder="搜索标签" data-none-results-text="未搜索到 {0}" title="选择标签" multiple>
+			@foreach ($tagList as $group=>$tags)
+			<optgroup label="{{$group}}">
+				@foreach ($tags as $tag)
+				<option value="{{$tag}}"  @if(in_array($tag,$oldData['tag_scope'])) selected @endif >{{$tag}}</option>
+				@endforeach
+			</optgroup>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-12">
+		<label class="control-label">活动规则</label>
+		<textarea class="form-control" name="rule" rows="10" placeholder="请输入活动规则" >{{$oldData['rule']}}</textarea>
+	</div>
+	<div class="form-group col-sm-12">
+		@csrf
+		<input type="hidden" name="id" id="id" value="{{$oldData['id']}}" />
+		<input id="send" type="submit" value="提交" class="btn btn-primary btn-block" />
+	</div>
+</form>
+@endsection

+ 96 - 0
resources/views/admin/lottery_recruitment/index.blade.php

@@ -0,0 +1,96 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+
+@if(check_auth('admin/lottery_recruitment/add'))
+	<div class="page-header">
+		<a href="{{url('admin/lottery_recruitment/add')}}" class="btn btn-primary">新增</a>
+	</div>
+@endif
+
+<form action="" method="get" class="form-horizontal form-line">
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="name" value="{{request('name','')}}" placeholder="请输入活动名称查询" />
+	</div>
+	<input type="submit" class="btn btn-sm btn-primary" value="查询"/>
+	<a href="{{url('admin/lottery_recruitment/index')}}" class="btn btn-sm btn-default" >重置</a>
+</form>
+
+<div class="row">
+	<div class="col-xs-12">	
+		<div class="table-responsive">
+			<table class="table table-striped table-bordered table-hover">
+				<thead>
+					<tr>
+						<th>活动ID</th>
+						<th>活动名称</th>
+						<th>开始时间</th>
+						<th>结束时间</th>
+						<th>活动状态</th>
+						<th>内部跳转</th>
+						<th>宣发链接</th>
+						<th>修改时间</th>
+						<th>操作</th>									
+					</tr>
+				</thead>
+				
+				<tbody>
+						@foreach ($list as $a)
+						<tr>
+							<th>{{$a['id']}}</th>
+							<td>{{$a['name']}}</td>
+							<td>{{date('Y/m/d H:i:s',$a['start_time'])}}</td>
+							<td>{{date('Y/m/d H:i:s',$a['end_time'])}}</td>
+							<td>
+								@if( $a['status'] )
+								停用
+								@else
+									@if( $a['start_time'] <= time() && $a['end_time'] <= time() )
+										已结束
+									@endif
+									@if( $a['start_time'] <= time() && $a['end_time'] > time() )
+										进行中
+									@endif
+									@if( $a['start_time'] > time() )
+										待进行
+									@endif
+								@endif
+							</td>
+							<td>/pages/activity/lottery?id={{$a['id']}}</td>
+							<td>{{$a['mp_urllink']}}</td>
+							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
+							<td>
+								@if(check_auth('admin/lottery_recruitment_reward/index'))
+								<a href="{{url('admin/lottery_recruitment_reward/index?'.http_build_query(['lottery_id'=>$a['id']]))}}" class="btn btn-sm btn-primary" >奖品配置</a>
+								@endif
+								@if(check_auth('admin/lottery_recruitment_record/index'))
+								<a href="{{url('admin/lottery_recruitment_record/index?'.http_build_query(['lottery_id'=>$a['id']]))}}" class="btn btn-sm btn-primary" >中奖记录</a>
+								@endif
+								@if(check_auth('admin/lottery_recruitment/edit'))
+								<a href="{{url('admin/lottery_recruitment/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
+								@endif
+								@if(check_auth('admin/lottery_recruitment/set_status'))
+									@if($a['status'])
+									<a data-url="{{url('admin/lottery_recruitment/set_status?'.http_build_query(['id'=>$a['id'],'status'=>0]))}}" class="set_status btn btn-sm btn-success" >启用</a>
+									@else
+									<a data-url="{{url('admin/lottery_recruitment/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a>
+									@endif
+								@endif
+							</td>							
+						</tr>  
+						@endforeach
+						<tr>
+							<td colspan="20" class="page">{{$list->render()}}</td>
+						</tr>
+						<tr>
+							<td colspan="20">总计 {{$list->total()}} 个活动</td>
+						</tr>
+				</tbody>
+				
+			</table>
+		</div>
+	</div>
+</div>
+@endsection

+ 89 - 0
resources/views/admin/lottery_recruitment_record/index.blade.php

@@ -0,0 +1,89 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+
+<form action="" method="get" class="form-horizontal form-line" name="thisform">
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<select name="lottery_id" required="required" class="form-control" >
+			<option value="0" > 选择活动 </option>
+			@foreach ($lotteryList as $value)
+				<option value="{{$value['id']}}" @if( request('lottery_id',0) == $value['id'] ) selected @endif>{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<select name="status" required="required" class="form-control" >
+			<option value="" > 状态 </option>
+			@foreach ($statusList as $value)
+				<option value="{{$value['id']}}" @if( !is_null(request('status'))  && request('status') == $value['id'] ) selected @endif>{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码查询" />
+	</div>
+	<button type="submit" onclick="alter_from_attr({'method':'get','action':`{{url('admin/lottery_recruitment_record/index')}}`})" class="btn btn-sm btn-primary"> 查询</button>
+	<a href="{{url('admin/lottery_recruitment_record/index')}}" class="btn btn-sm btn-default" >重置</a>
+	@if( check_auth('admin/lottery_recruitment_record/down_excel') )
+		<button type="button" onclick="alter_from_attr({'method':'get','action':`{{url('admin/lottery_recruitment_record/down_excel')}}`})" class="btn btn-sm btn-primary"> 下载</button>
+	@endif
+</form>
+<div class="row">
+	<div class="col-xs-12">	
+		<div class="table-responsive">
+			<table class="table table-striped table-bordered table-hover">
+				<thead>
+					<tr>
+						<th>记录ID</th>
+						<th>活动ID</th>
+						<th>活动名称</th>
+						<th>客户编码</th>
+						<th>客户昵称</th>
+						<th>奖品名称</th>
+						<th>状态</th>
+						<th>收货信息</th>
+						<th>中奖时间</th>
+						<th>修改时间</th>
+						<th>操作</th>									
+					</tr>
+				</thead>
+				
+				<tbody>
+						@foreach ($list as $a)
+						<tr>
+							<th>{{$a['id']}}</th>
+							<td>{{$a['lottery_id']}}</td>
+							<td>{{$a['active_name']}}</td>
+							<td>{{$a['custom_code']}}</td>
+							<td>{{$a['username']}}</td>
+							<td>{{$a['reward_name']}}</td>
+							<td>{{$a['state']}}</td>
+							<td>{{$a['contact_name']}} {{$a['contact_phone']}} {{$a['contact_province']}} {{$a['contact_city']}} {{$a['contact_area']}} {{$a['contact_addr']}} {{$a['contact_shop']}}</td>
+							<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
+							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
+							<td>
+								@if(check_auth('admin/lottery_recruitment_record/set_status'))
+									@if( $a['status'] != 8 )
+									<a data-url="{{url('admin/lottery_recruitment_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>8]))}}" class="set_status btn btn-sm btn-success" >完成</a>
+									@else
+									<!-- <a data-url="{{url('admin/lottery_recruitment_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a> -->
+									@endif
+								@endif
+							</td>							
+						</tr>  
+						@endforeach
+						<tr>
+							<td colspan="20" class="page">{{$list->render()}}</td>
+						</tr>
+						<tr>
+							<td colspan="20">总计 {{$list->total()}} 个记录</td>
+						</tr>
+				</tbody>
+				
+			</table>
+		</div>
+	</div>
+</div>
+@endsection

+ 53 - 0
resources/views/admin/lottery_recruitment_reward/add.blade.php

@@ -0,0 +1,53 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+<form class="post-form" action="" method="post">
+	<div class="form-group col-sm-2">
+		<label class="control-label">奖品图片 [200*200]</label>
+		<div id="thumb">
+			<a id="thumb-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat('')}}" height="100" />
+			</a>
+			<input type="hidden" name="reward_thumb" value="" id="input-thumb" />
+		</div>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品名称</label>
+		<input class="form-control" required="required" type="text" placeholder="奖品名称,建议4~15字" name="reward_name" maxlength="15" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品类型</label>
+		<select name="reward_type" required="required" class="form-control" >
+			@foreach ($typeList as $value)
+				<option value="{{$value['id']}}" >{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">所属活动</label>
+		<select name="lottery_id" required="required" class="form-control" >
+			@foreach ($lotteryList as $value)
+				<option value="{{$value['id']}}" @if( request('lottery_id',0) == $value['id'] ) selected @endif>{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品份数</label>
+		<input class="form-control" required="required" type="number" placeholder="奖品份数" name="reward_total" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品信息</label>
+		<input class="form-control" type="text" placeholder="积分数量,红包金额,优惠券编码" name="reward_info" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">中奖概率</label>
+		<input class="form-control" required="required" type="text" min="0" placeholder="中奖概率" name="probability" max="{{$maxProbability}}" value="" />
+	</div>
+	<div class="form-group col-sm-12">
+		@csrf
+		<input id="send" type="submit" value="提交" class="btn btn-primary btn-block" />
+	</div>
+</form>
+@endsection

+ 54 - 0
resources/views/admin/lottery_recruitment_reward/edit.blade.php

@@ -0,0 +1,54 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+<form class="post-form" action="" method="post">
+	<div class="form-group col-sm-2">
+		<label class="control-label">奖品图片 [200*200]</label>
+		<div id="thumb">
+			<a id="thumb-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat($oldData['reward_thumb'])}}" height="100" />
+			</a>
+			<input type="hidden" name="reward_thumb" value="" id="input-thumb" />
+		</div>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品名称</label>
+		<input class="form-control" required="required" type="text" placeholder="奖品名称,建议4~15字" name="reward_name" maxlength="15" value="{{$oldData['reward_name']}}" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品类型</label>
+		<select name="reward_type" required="required" class="form-control" >
+			@foreach ($typeList as $value)
+				<option value="{{$value['id']}}" @if( $oldData['reward_type'] == $value['id'] ) selected @endif >{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">所属活动</label>
+		<select name="lottery_id" required="required" class="form-control" >
+			@foreach ($lotteryList as $value)
+				<option value="{{$value['id']}}" @if( $oldData['lottery_id'] == $value['id'] ) selected @endif>{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品份数</label>
+		<input class="form-control" required="required" type="number" placeholder="奖品份数" name="reward_total" value="{{$oldData['reward_total']}}" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">奖品信息</label>
+		<input class="form-control" type="text" placeholder="积分数量,红包金额,优惠券编码" name="reward_info" value="{{$oldData['reward_info']}}" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">中奖概率</label>
+		<input class="form-control" required="required" type="number" step="0.01" min="0" placeholder="中奖概率" name="probability" max="{{$maxProbability}}" value="{{$oldData['probability']}}" />
+	</div>
+	<div class="form-group col-sm-12">
+		@csrf
+		<input type="hidden" name="id" id="id" value="{{$oldData['id']}}" />
+		<input id="send" type="submit" value="提交" class="btn btn-primary btn-block" />
+	</div>
+</form>
+@endsection

+ 93 - 0
resources/views/admin/lottery_recruitment_reward/index.blade.php

@@ -0,0 +1,93 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+
+@if(check_auth('admin/lottery_recruitment_reward/add'))
+	<div class="page-header">
+		<a href="{{url('admin/lottery_recruitment_reward/add?'.http_build_query(['lottery_id'=>request('lottery_id',0)]))}}" class="btn btn-primary">新增</a>
+	</div>
+@endif
+<form action="" method="get" class="form-horizontal form-line">
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<select name="lottery_id" required="required" class="form-control" >
+			<option value="0" > 选择活动 </option>
+			@foreach ($lotteryList as $value)
+				<option value="{{$value['id']}}" @if( request('lottery_id',0) == $value['id'] ) selected @endif>{{$value['name']}}</option>
+			@endforeach
+		</select>
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="name" value="{{request('name','')}}" placeholder="请输入奖品名称查询" />
+	</div>
+	<input type="submit" class="btn btn-sm btn-primary" value="查询"/>
+	<a href="{{url('admin/lottery_recruitment_reward/index')}}" class="btn btn-sm btn-default" >重置</a>
+</form>
+<div class="row">
+	<div class="col-xs-12">	
+		<p class="text-center text-red">奖项请设置3-7个,默认自带一个谢谢参与奖项</p>
+	</div>
+</div>
+<div class="row">
+	<div class="col-xs-12">	
+		<div class="table-responsive">
+			<table class="table table-striped table-bordered table-hover">
+				<thead>
+					<tr>
+						<th>奖品ID</th>
+						<th>奖品名称</th>
+						<th>奖品类型</th>
+						<th>奖品信息</th>
+						<th>奖品份数</th>
+						<th>中奖概率</th>
+						<th>所属活动</th>
+						<th>状态</th>
+						<th>修改时间</th>
+						<th>操作</th>									
+					</tr>
+				</thead>
+				
+				<tbody>
+						@foreach ($list as $a)
+						<tr>
+							<th>{{$a['id']}}</th>
+							<td>{{$a['reward_name']}}</td>
+							<td>{{$a['reward_type']}}</td>
+							<td>{{$a['reward_info']}}</td>
+							<td>{{$a['reward_total']}}</td>
+							<td>{{$a['probability']}}</td>
+							<td>
+								@foreach ($lotteryList as $value)
+									@if( $a['lottery_id'] == $value['id'] ) {{$value['name']}} @endif
+								@endforeach
+							</td>
+							<td>{{$a['status']?'停用':'启用'}}</td>
+							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
+							<td>
+								@if(check_auth('admin/lottery_recruitment_reward/edit'))
+								<a href="{{url('admin/lottery_recruitment_reward/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
+								@endif
+								@if(check_auth('admin/lottery_recruitment_reward/set_status'))
+									@if($a['status'])
+									<a data-url="{{url('admin/lottery_recruitment_reward/set_status?'.http_build_query(['id'=>$a['id'],'status'=>0]))}}" class="set_status btn btn-sm btn-success" >启用</a>
+									@else
+									<a data-url="{{url('admin/lottery_recruitment_reward/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a>
+									@endif
+								@endif
+							</td>							
+						</tr>  
+						@endforeach
+						<tr>
+							<td colspan="20" class="page">{{$list->render()}}</td>
+						</tr>
+						<tr>
+							<td colspan="20">总计 {{$list->total()}} 个商店</td>
+						</tr>
+				</tbody>
+				
+			</table>
+		</div>
+	</div>
+</div>
+@endsection

+ 0 - 3
resources/views/admin/lottery_riddle/index.blade.php

@@ -78,9 +78,6 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 									<a data-url="{{url('admin/lottery_riddle/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a>
 									@endif
 								@endif
-								@if(check_auth('admin/lottery_riddle/get_poster'))
-								<a href="{{url('admin/lottery_riddle/get_poster?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-success" >海报</a>
-								@endif
 							</td>							
 						</tr>  
 						@endforeach

+ 3 - 3
resources/views/admin/lottery_riddle_record/index.blade.php

@@ -64,11 +64,11 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
 							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
 							<td>
-								@if(check_auth('admin/lottery_order_record/set_status'))
+								@if(check_auth('admin/lottery_riddle_record/set_status'))
 									@if( $a['status'] != 8 )
-									<a data-url="{{url('admin/lottery_order_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>8]))}}" class="set_status btn btn-sm btn-success" >完成</a>
+									<a data-url="{{url('admin/lottery_riddle_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>8]))}}" class="set_status btn btn-sm btn-success" >完成</a>
 									@else
-									<!-- <a data-url="{{url('admin/lottery_order_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a> -->
+									<!-- <a data-url="{{url('admin/lottery_riddle_record/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a> -->
 									@endif
 								@endif
 							</td>							

+ 7 - 4
resources/views/admin/poster/index.blade.php

@@ -16,10 +16,13 @@
 		<div class="form-group col-sm-12">
 			<label class="control-label">活动地址</label>
 			<select name="url" class="form-control" id="typeId" required="required">
-				<option value="pages/coupon/active" >领劵活动地址</option>
-				<option value="pages/score/clockin">打卡活动地址</option>
-				<option value="pages/recruitment/index">拉新活动地址</option>
-				<option value="pages/orders/lottery">下单抽奖活动</option>
+				<option value="pages/coupon/active" >领劵活动</option>
+				<option value="pages/score/clockin">打卡活动</option>
+				<option value="pages/recruitment/index">拉新活动</option>
+				<option value="pages/orders/lottery">下单抽奖</option>
+				<option value="pages/activity/index">答题活动</option>
+				<option value="pages/activity/lottery">答题抽奖</option>
+				<option value="pages/recruitment/lottery">拉新抽奖</option>
 			</select>
 		</div>
 		<div class="form-group col-sm-12">

+ 0 - 3
resources/views/admin/riddle_active/index.blade.php

@@ -75,9 +75,6 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 									<a data-url="{{url('admin/riddle_active/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a>
 									@endif
 								@endif
-								@if(check_auth('admin/riddle_active/get_poster'))
-								<!-- <a href="{{url('admin/riddle_active/get_poster?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-success" >海报</a> -->
-								@endif
 							</td>							
 						</tr>  
 						@endforeach

+ 16 - 0
routes/api.php

@@ -320,3 +320,19 @@ Route::any('video_exam_record/hand_in',[App\Http\Controllers\Api\Video\ExamRecor
 Route::any('video_exam_record/get_report',[App\Http\Controllers\Api\Video\ExamRecord::class,'get_report']);
 Route::any('video_exam_record/get_report_last',[App\Http\Controllers\Api\Video\ExamRecord::class,'get_report_last']);
 
+/**
+ * 拉新抽奖
+ */
+// 获取答题抽奖配置
+Route::any('lottery_recruitment/get_detail',[\App\Http\Controllers\Api\Lottery\Recruitment::class,'get_detail']);
+// 进行抽奖
+Route::any('lottery_recruitment/get_reward',[\App\Http\Controllers\Api\Lottery\Recruitment::class,'get_reward']);
+
+/**
+ * 拉新抽奖抽奖记录
+ */
+// 获取列表
+Route::any('lottery_recruitment_record/get_list',[\App\Http\Controllers\Api\Lottery\RecruitmentRecord::class,'get_list']);
+Route::any('lottery_recruitment_record/get_list_all',[\App\Http\Controllers\Api\Lottery\RecruitmentRecord::class,'get_list_all']);
+// 设置地址
+Route::any('lottery_recruitment_record/set_addr',[\App\Http\Controllers\Api\Lottery\RecruitmentRecord::class,'set_addr']);

+ 29 - 4
routes/web.php

@@ -599,8 +599,6 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     Route::any('lottery_riddle/edit',[App\Http\Controllers\Admin\LotteryRiddle::class,'edit']);
     // 状态
     Route::any('lottery_riddle/set_status',[App\Http\Controllers\Admin\LotteryRiddle::class,'set_status']);
-    // 状态
-    Route::any('lottery_riddle/get_poster',[App\Http\Controllers\Admin\LotteryRiddle::class,'get_poster']);
 
     /* 答题抽奖 奖品配置 */
     // 列表
@@ -630,8 +628,6 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     Route::any('riddle_active/edit',[App\Http\Controllers\Admin\RiddleActive::class,'edit']);
     // 状态
     Route::any('riddle_active/set_status',[App\Http\Controllers\Admin\RiddleActive::class,'set_status']);
-    // 状态
-    Route::any('riddle_active/get_poster',[App\Http\Controllers\Admin\RiddleActive::class,'get_poster']);
 
     /* 灯谜题目 */
     // 列表
@@ -738,4 +734,33 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     /* 答题记录下载 */
     Route::any('video_exam_answer/down_excel',[App\Http\Controllers\Admin\VideoExamAnswer::class,'down_excel']);
 
+
+    /* 拉新抽奖活动 */
+    // 列表
+    Route::any('lottery_recruitment/index',[App\Http\Controllers\Admin\LotteryRecruitment::class,'index']);
+    // 详情
+    Route::any('lottery_recruitment/add',[App\Http\Controllers\Admin\LotteryRecruitment::class,'add']);
+    // 详情
+    Route::any('lottery_recruitment/edit',[App\Http\Controllers\Admin\LotteryRecruitment::class,'edit']);
+    // 状态
+    Route::any('lottery_recruitment/set_status',[App\Http\Controllers\Admin\LotteryRecruitment::class,'set_status']);
+
+    /* 答题抽奖 奖品配置 */
+    // 列表
+    Route::any('lottery_recruitment_reward/index',[App\Http\Controllers\Admin\LotteryRecruitmentReward::class,'index']);
+    // 详情
+    Route::any('lottery_recruitment_reward/add',[App\Http\Controllers\Admin\LotteryRecruitmentReward::class,'add']);
+    // 详情
+    Route::any('lottery_recruitment_reward/edit',[App\Http\Controllers\Admin\LotteryRecruitmentReward::class,'edit']);
+    // 状态
+    Route::any('lottery_recruitment_reward/set_status',[App\Http\Controllers\Admin\LotteryRecruitmentReward::class,'set_status']);
+
+    /* 答题抽奖记录 */
+    // 列表
+    Route::any('lottery_recruitment_record/index',[App\Http\Controllers\Admin\LotteryRecruitmentRecord::class,'index']);
+    // 状态
+    Route::any('lottery_recruitment_record/set_status',[App\Http\Controllers\Admin\LotteryRecruitmentRecord::class,'set_status']);
+    // 状态
+    Route::any('lottery_recruitment_record/down_excel',[App\Http\Controllers\Admin\LotteryRecruitmentRecord::class,'down_excel']);
+
 });