Ver Fonte

【Add】抽奖管理

liuxiangxin há 6 meses atrás
pai
commit
0b28ca56a7

+ 185 - 0
app/Http/Controllers/Admin/LotteryScore.php

@@ -0,0 +1,185 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\LotteryScore as Request;
+use App\Models\Lottery\Score as Model;
+use App\Models\City;
+use App\Models\Lottery\ScoreReward;
+use App\Models\WeiBan\Tags as WeiBanTags;
+
+/**
+ * 优惠券自动发放规则
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryScore extends Auth{
+	
+	protected function _initialize(){
+		parent::_initialize();
+		$this->assign('breadcrumb1','积分管理');
+		$this->assign('breadcrumb2','积分抽奖');
+	}
+
+	/**
+	 * 列表页
+	 * 
+	 * */
+    public function index(Model $Model){
+		// 查询条件
+		$map 					= [];
+		// 查询数据
+		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// 重组
+			$list[$key]			= $value;
+		}
+		// 分配数据
+		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+		$this->assign('list',$list);
+		// 加载模板
+		return 					$this->fetch();
+    }
+
+	/**
+	 * 添加
+	 * 
+	 * */
+	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['need_score']		= request('need_score',0);
+			$data['need_old_score']	= request('need_old_score',0);
+			$data['rule']			= request('rule','');
+			$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['need_score']		= request('need_score',0);
+			$data['need_old_score']	= request('need_old_score',0);
+			$data['rule']			= request('rule','');
+			$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,ScoreReward $ScoreReward){
+		// 验证参数
+		$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		= $ScoreReward->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'=>'']);
+	}
+
+}

+ 70 - 0
app/Http/Controllers/Admin/LotteryScoreRecord.php

@@ -0,0 +1,70 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\LotteryScoreReward as Request;
+use App\Models\Coupon;
+use App\Models\Lottery\ScoreRecord as Model;
+use App\Models\Lottery\Score as LotteryScore;
+/**
+ * 抽奖记录
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryScoreRecord extends Auth{
+	
+	protected function _initialize(){
+		parent::_initialize();
+		$this->assign('breadcrumb1','积分抽奖');
+		$this->assign('breadcrumb2','抽奖记录');
+	}
+
+	/**
+	 * 列表页
+	 * 
+	 * */
+    public function index(Model $Model,LotteryScore $LotteryScore){
+		// 查询条件
+		$map 					= [];
+		// 查询数据
+		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// 重组
+			$list[$key]			= $value;
+		}
+		// 获取列表
+		$lotteryList 			= $LotteryScore->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 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'=>'']);
+	}
+
+}

+ 202 - 0
app/Http/Controllers/Admin/LotteryScoreReward.php

@@ -0,0 +1,202 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Http\Requests\Admin\LotteryScoreReward as Request;
+use App\Models\Coupon;
+use App\Models\Lottery\ScoreReward as Model;
+use App\Models\Lottery\Score as LotteryScore;
+/**
+ * 抽奖奖品
+ *
+ * @author    刘相欣
+ *
+ */
+class LotteryScoreReward extends Auth{
+	
+	protected function _initialize(){
+		parent::_initialize();
+		$this->assign('breadcrumb1','积分抽奖');
+		$this->assign('breadcrumb2','抽奖奖品');
+	}
+
+	/**
+	 * 列表页
+	 * 
+	 * */
+    public function index(Model $Model,LotteryScore $LotteryScore){
+		// 查询条件
+		$map 					= [];
+		// 查询数据
+		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// 获取类型名称
+			$value['reward_type'] = $Model->getRewardType($value['id'],'name');
+			// 重组
+			$list[$key]			= $value;
+		}
+		// 获取列表
+		$lotteryList 			= $LotteryScore->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,LotteryScore $LotteryScore,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 				= $LotteryScore->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,LotteryScore $LotteryScore,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 				= $LotteryScore->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'=>'']);
+	}
+
+}

+ 26 - 21
app/Http/Controllers/Admin/Orders.php

@@ -286,8 +286,9 @@ class Orders extends Auth{
 										'orders_product.sku_attr_names as product_spec',
 										'orders_product.product_thumb',
 										'orders_product.buy_num',
-										'orders_product.pay_total',
+										'orders_product.price_total',
 										'orders_product.coupon_total',
+										'orders_product.pay_total',
 										'orders_product.status',
 										'orders_product.insert_time',
 										'custom.username as custom_name','custom.weiban_extid as weiban_extid',
@@ -301,7 +302,8 @@ class Orders extends Auth{
 			$value['order_id']		= $Model->idToCode($value['order_id']);
 			$value['status']		= $Model->getState($value['status'],'state');
 			$value['custom_uid']	= $Custom->idToCode($value['custom_uid']);
-			$value['product_price']	= $value['buy_num'] ? ($value['pay_total'] / $value['buy_num']) : $value['buy_num'];
+			$value['product_price']	= $value['buy_num'] ? ($value['price_total'] / $value['buy_num']) : $value['buy_num'];
+			$value['pay_price']		= $value['buy_num'] ? ($value['pay_total'] / $value['buy_num']) : $value['buy_num'];
 			// 重组
 			$data[$value['order_id']]['order_id'] = $value['order_id'];
 			$data[$value['order_id']]['custom_uid'] = $value['custom_uid'];
@@ -317,14 +319,14 @@ class Orders extends Auth{
 			$data[$value['order_id']]['contact_area'] = $value['contact_area'];
 			$data[$value['order_id']]['contact_addr'] = $value['contact_addr'] .($value['contact_shop'] ? '【'.$value['contact_shop'].'】' : '');
 			// 子订单
-			$data[$value['order_id']]['product'][] 	  = ['product_name'=>$value['product_name'],'product_spec'=>$value['product_spec'],'product_thumb'=>$value['product_thumb'],'product_price'=>$value['product_price'],'buy_num'=>$value['buy_num'],'pay_total'=>$value['pay_total'],'coupon_total'=>$value['coupon_total']];
+			$data[$value['order_id']]['product'][] 	  = ['product_name'=>$value['product_name'],'product_spec'=>$value['product_spec'],'product_thumb'=>$value['product_thumb'],'product_price'=>$value['product_price'],'pay_price'=>$value['pay_price'],'buy_num'=>$value['buy_num'],'pay_total'=>$value['pay_total'],'price_total'=>$value['price_total'],'coupon_total'=>$value['coupon_total']];
 		}
 
 		try {
 			// 去下载
 			$this->toDown($data);
 		} catch (\Throwable $th) {
-			dd($th);
+			echo $th->getMessage();
 		}
 		
 	}
@@ -357,8 +359,8 @@ class Orders extends Auth{
 				$sheet->mergeCells('H'.$row.':'.'H'.($row+$count-1));
 				$sheet->mergeCells('I'.$row.':'.'I'.($row+$count-1));
 				$sheet->mergeCells('J'.$row.':'.'J'.($row+$count-1));
-				$sheet->mergeCells('Q'.$row.':'.'Q'.($row+$count-1));
 				$sheet->mergeCells('R'.$row.':'.'R'.($row+$count-1));
+				$sheet->mergeCells('S'.$row.':'.'S'.($row+$count-1));
 			}
 			// 单元格内容写入
 			$sheet->setCellValue('A'.$row, $value['order_id']);
@@ -371,16 +373,17 @@ class Orders extends Auth{
 			$sheet->setCellValue('H'.$row, $value['contact_city']);
 			$sheet->setCellValue('I'.$row, $value['contact_area']);
 			$sheet->setCellValue('J'.$row, $value['contact_addr']);
-			$sheet->setCellValue('Q'.$row, $value['weiban_extid']);
-			$sheet->setCellValue('R'.$row, date('Y-m-d H:i:s',$value['insert_time']));
+			$sheet->setCellValue('R'.$row, $value['weiban_extid']);
+			$sheet->setCellValue('S'.$row, date('Y-m-d H:i:s',$value['insert_time']));
 			// 循环产品
 			foreach ($value['product'] as $v) {
 				$sheet->setCellValue('K'.$row, $v['product_name']);
 				$sheet->setCellValue('L'.$row, $v['product_spec']);
 				$sheet->setCellValue('M'.$row, $v['product_price']);
-				$sheet->setCellValue('N'.$row, $v['buy_num']);
-				$sheet->setCellValue('O'.$row, $v['coupon_total']);
-				$sheet->setCellValue('P'.$row, $v['pay_total']);
+				$sheet->setCellValue('N'.$row, $v['pay_price']);
+				$sheet->setCellValue('O'.$row, $v['buy_num']);
+				$sheet->setCellValue('P'.$row, $v['coupon_total']);
+				$sheet->setCellValue('Q'.$row, $v['pay_total']);
 				// 函数自增
 				$row++;
 			}
@@ -419,14 +422,15 @@ class Orders extends Auth{
 		$sheet->getColumnDimension('N')->setWidth(10);
 		$sheet->getColumnDimension('O')->setWidth(10);
 		$sheet->getColumnDimension('P')->setWidth(10);
-		$sheet->getColumnDimension('Q')->setWidth(50);
-		$sheet->getColumnDimension('R')->setWidth(20);
+		$sheet->getColumnDimension('Q')->setWidth(10);
+		$sheet->getColumnDimension('R')->setWidth(50);
+		$sheet->getColumnDimension('S')->setWidth(20);
 		// 默认高度
 		$sheet->getDefaultRowDimension()->setRowHeight(18);
 		// 加粗第一行
-		$sheet->getStyle('A:R')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
-		$sheet->getStyle('A1:R1')->getFont()->setBold(true);
-		$sheet->getStyle('A1:R1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
+		$sheet->getStyle('A:S')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+		$sheet->getStyle('A1:S1')->getFont()->setBold(true);
+		$sheet->getStyle('A1:S1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
 		// 设置表格标题
 		$sheet
 		->setCellValue('A1', '订单ID')
@@ -441,12 +445,13 @@ class Orders extends Auth{
 		->setCellValue('J1', '收货地址')
 		->setCellValue('K1', '产品名称')
 		->setCellValue('L1', '产品规格')
-		->setCellValue('M1', '产品价格')
-		->setCellValue('N1', '产品数量')
-		->setCellValue('O1', '优惠金额')
-		->setCellValue('P1', '产品金额')
-		->setCellValue('Q1', '微伴ID')
-		->setCellValue('R1', '下单时间');
+		->setCellValue('M1', '产品单价')
+		->setCellValue('N1', '折后单价')
+		->setCellValue('O1', '产品数量')
+		->setCellValue('P1', '优惠金额')
+		->setCellValue('Q1', '产品金额')
+		->setCellValue('R1', '微伴ID')
+		->setCellValue('S1', '下单时间');
 		// 返回结果
 		return 					$sheet;
 	}

+ 192 - 0
app/Http/Controllers/Api/Lottery/Score.php

@@ -0,0 +1,192 @@
+<?php namespace App\Http\Controllers\Api\Lottery;
+
+use App\Http\Controllers\Api\Api;
+use App\Models\Lottery\Score as Model;
+use App\Models\Custom;
+use App\Models\CustomCoupon;
+use App\Models\CustomScore;
+use App\Models\Lottery\ScoreRecord;
+use App\Models\Lottery\ScoreReward as ScoreReward;
+use App\Models\WeiBan\Tags as WeiBanTags;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 积分抽奖
+ * 
+ * @author 刘相欣
+ * 
+ * */
+class Score extends Api{
+
+	/**
+	 * 获取抽奖配置		/api/lottery_score/get_detail
+	 * 
+	 * 
+	 * */
+	public function get_detail(Model $Model,Custom $Custom,ScoreReward $ScoreReward,WeiBanTags $WeiBanTags){
+		// 接口验签
+		// $this->verify_sign();
+		// 检查登录
+		$uid							= $this->checkLogin();
+		// 获取客户信息
+		$custom							= $Custom->getOne($uid);
+		// 如果存在的话
+		if( !$custom )					return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
+		// 客户的城市ID
+		$cityId							= empty($custom['city_id']) ? 0 : $custom['city_id'];
+		// 获取客户城市的数据
+		$data			                = $Model->getOneByCity($cityId);
+		// 如果存在的话
+		if( !$data )					return json_send(['code'=>'error','msg'=>'暂无活动','data'=>$data]);
+		// 奖品
+		$reward 						= $ScoreReward->getListByLottery($data['id']);
+		// 活动暂无奖品
+		if( !$reward )					return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
+		// 通过活动ID,查询奖品
+		$data['rewardList']				= $reward;
+		// logo
+		$data['logo']					= $data['logo'] ? path_compat($data['logo']) : '';
+		// 判断用户是不是活动期间注册的以判断新老用户,获取对应积分
+		$data['need_score']				= ($custom['insert_time'] >= $data['start_time'] && $custom['insert_time'] <= $data['end_time']) ? $data['need_score'] : $data['need_old_score'];
+		// 默认可以参加活动
+		$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;
+			}
+		}
+		// 删除不必要的数据
+		unset($data['need_old_score'],$data['tag_scope'],$data['city_ids']);
+		// 返回结果
+		return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
+	}
+
+	/**
+	 * 积分抽奖		/api/lottery_score/get_reward
+	 * 
+	 * */
+	public function get_reward(Model $Model,Custom $Custom,ScoreReward $ScoreReward,WeiBanTags $WeiBanTags,CustomScore $CustomScore,CustomCoupon $CustomCoupon,ScoreRecord $ScoreRecord){
+		// 接口验签
+		// $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]);
+		// 奖品
+		$reward 						= $ScoreReward->getListByLottery($data['id']);
+		// 活动暂无奖品
+		if( !$reward )					return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
+		// 判断用户是不是活动期间注册的以判断新老用户,获取对应积分
+		$data['need_score']				= ($custom['insert_time'] >= $data['start_time'] && $custom['insert_time'] <= $data['end_time']) ? $data['need_score'] : $data['need_old_score'];
+		// 默认可以参加活动
+		$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'=>'不符合参与条件']]);
+		// 组合数据,写入订单表,子表
+		DB::beginTransaction();
+		try{
+			// 扣减积分
+			$result 						= $CustomScore->trade($uid,$lotteryId,($data['need_score']*-1),7,1);
+			// 如果积分扣减失败
+			if( isset($result['error']) )	{
+				// 回退数据
+				DB::rollBack();
+				return 						json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
+			}
+			// 获取奖励结果
+			$rewardIndex 					= $ScoreReward->getRewardResult($reward);
+			// 如果中奖,下标不是0
+			if( $rewardIndex )				{
+				// 获取奖品
+				$rewardResult				= $reward[$rewardIndex];
+				// 奖品记录ID
+				if( !empty($rewardResult['id']) ){
+					// 记录,默认状态为1,进行中
+					$record					= ['custom_uid'=>$uid,'lottery_id'=>$lotteryId,'reward_id'=>$rewardResult['id'],'reward_name'=>$rewardResult['reward_name'],'status'=>1];
+					// 如果是积分
+					if( $rewardResult['reward_type'] == 1 ){
+						// 积分大于0
+						if( $rewardResult['reward_info'] > 0 ){
+							// 积分发放
+							$result 		= $CustomScore->trade($uid,$lotteryId,$rewardResult['reward_info'],7,2);
+							// 发放失败,改为未中奖
+							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;
+						}
+					}
+					// 如果是实物,要求填写地址,状态设置为0
+					if( $rewardResult['reward_type'] == 5 ) $record['status'] = 0;
+					// 中奖才进行记录
+					if( $rewardIndex ) 		{
+						// 奖品数量减少
+						$ScoreReward->edit($rewardResult['id'],['reward_total'=>DB::raw('reward_total+-1')]);
+						// 扣减数量
+						$ScoreRecord->add($record);
+					}
+				}
+			}
+			// 提交事务
+			DB::commit();
+			// 返回结果
+			return							json_send(['code'=>'success','msg'=>'抽奖成功','data'=>['rewardList'=>$reward,'rewardIndex'=>$rewardIndex]]);
+			// 异常处理
+		} catch (\Throwable $th) {
+			// 回退数据
+			DB::rollBack();
+			// 下单失败提示
+			return							json_send(['code'=>'error','msg'=>'抽奖失败,请重试','data'=>['error'=>$th->getMessage().$th->getLine()]]);
+		}	
+
+	}
+	
+}

+ 51 - 0
app/Http/Requests/Admin/LotteryScore.php

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

+ 52 - 0
app/Http/Requests/Admin/LotteryScoreReward.php

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

+ 2 - 2
app/Models/Custom.php

@@ -81,7 +81,7 @@ class Custom extends Model
     public function getOne($uid)
     {
         // 返回结果
-        $custom         = $this->query()->where([['uid','=',$uid]])->first(['uid','external_userid','weiban_extid','phone','userpic','username','sex','city_id','status']);
+        $custom         = $this->query()->where([['uid','=',$uid]])->first(['uid','external_userid','weiban_extid','phone','userpic','username','sex','city_id','status','insert_time']);
         // 返回结果
         if( !$custom )  return [];
         // 数据结构
@@ -98,7 +98,7 @@ class Custom extends Model
     public function getOneByPhone($phone)
     {
         // 返回结果
-        $custom         = $this->query()->where([['phone','=',$phone]])->first(['uid','external_userid','weiban_extid','phone','userpic','username','sex','city_id','status']);
+        $custom         = $this->query()->where([['phone','=',$phone]])->first(['uid','external_userid','weiban_extid','phone','userpic','username','sex','city_id','status','insert_time']);
         // 返回结果
         if( !$custom )  return [];
         // 数据结构

+ 28 - 0
app/Models/CustomCoupon.php

@@ -182,4 +182,32 @@ class CustomCoupon extends Model
     }
 
 
+    /**
+     * 发放优惠券
+     * 
+     * @param   int  $couponId  优惠券ID
+     * @param   int  $customUid 客户ID
+     * 
+     */
+    public function giveCoupon($couponId,$customUid){
+        // 达标的是否已经发送过优惠券
+        $havaCoupon			                            = $this->query()->where([['custom_uid','=',$customUid],['coupon_id','=',$couponId]])->first(['status']);
+        // 已经发过优惠券的,不发
+        if( $havaCoupon )                               return 0;
+        // 优惠券
+        $Coupon				                            = new \App\Models\Coupon();
+        // 获取优惠券的可用时间
+        $couponData			                            = $Coupon->query()->where([['id','=',$couponId],['status','=','0']])->first(['issue_total','status','exp_time']);
+        // 如果不存在数据,发送失败
+        if( !$couponData || $couponData['status'] )     return 0;
+        // 查询总共发放数量
+        $total                                          = $this->query()->where([['coupon_id','=',$couponId]])->count();
+        // 数量超过的话。不发
+        if( $total >= $couponData['issue_total'] )      return 0;
+        // 时间转时间
+        $expTime			                            = $Coupon->getExpTime($couponData['exp_time']);
+        // 发送优惠券
+        return                                          $this->add(['coupon_id'=>$couponId,'custom_uid'=>$customUid,'exp_time'=>$expTime]);
+    }
+
 }

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

@@ -0,0 +1,144 @@
+<?php namespace App\Models\Lottery;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 积分抽奖模型
+ * 
+ */
+class Score extends Model
+{
+    use HasFactory;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_score';
+    // 是否主动维护时间戳
+    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:score:list');
+        // 不存在数据
+        if ( !$list ) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status','=',0]])->get(['id','name','logo','need_score','need_old_score','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:score: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();
+        // 列表数据不存在
+        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;
+    }
+
+}

+ 56 - 0
app/Models/Lottery/ScoreRecord.php

@@ -0,0 +1,56 @@
+<?php namespace App\Models\Lottery;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use App\Models\Traits\Lottery\RewardType;
+
+/**
+ * 抽奖记录模型
+ * 
+ */
+class ScoreRecord extends Model
+{
+    use HasFactory,RewardType;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_score_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/ScoreReward.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 ScoreReward extends Model
+{
+    use HasFactory,RewardType;
+
+    // 与模型关联的表名
+    protected $table = 'lottery_score_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:score: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:score: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){
+        // 从1开始
+		$offset							= 1;
+		// 判断抽奖结果
+		$randInt						= random_int($offset,100);
+		// 中奖下标
+		$index							= 0;
+		// 循环奖品
+		foreach ($reward as $key => $value) {
+            // 概率为0 或者产品份数为0,不参与
+            if( $value['probability'] <= 0 || $value['reward_total']<= 0 )  continue;
+			// 开始数值
+			$start 						= $offset;
+			// 结束数值
+			$end						= $value['probability'] ? $offset + $value['probability'] : 0;
+			// 重新计算开始数值
+			$offset						= $offset ? $end : $offset;
+			// 区间内即抽中
+			if( $start <= $randInt && $end >= $randInt ) $index = $key;
+		}
+        // 是否中奖,以及奖项下标
+        return                          $index;
+    }
+
+}

+ 68 - 0
app/Models/Traits/Lottery/RewardType.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace App\Models\Traits\Lottery;
+
+
+/**
+ * 奖品类型
+ * 
+ */
+trait RewardType
+{
+
+    // 奖品类型
+    private     $rewardType        =   ['1'=>[
+                                        'id'            =>1,
+                                        // 类型名称
+                                        'name'          =>'积分',
+                                    ],'2'=>[
+                                        'id'            =>2,
+                                        // 类型名称
+                                        'name'          =>'优惠券',
+                                    ],'3'=>[
+                                        'id'            =>3,
+                                        // 类型名称
+                                        'name'          =>'红包',
+                                    ],'4'=>[
+                                        'id'            =>4,
+                                        // 类型名称
+                                        'name'          =>'虚拟物品',
+                                    ],'5'=>[
+                                        'id'            =>5,
+                                        // 类型名称
+                                        'name'          =>'实物',
+                                    ],'6'=>[
+                                        'id'            =>6,
+                                        // 类型名称
+                                        'name'          =>'其他',
+                                    ]];
+
+    /**
+     * 交易类型列表
+     * 
+     */
+    public function getRewardTypeList(){
+        // 返回数据
+        return                  $this->rewardType;
+    }
+
+    /**
+     * 获取交易类型
+     * 
+     * @param int       $id         类型ID
+     * @param string    $field      字段
+     * 
+     */
+    public function getRewardType($id,$field=''){
+        // 获取数据
+        $list               = $this->getRewardTypeList();
+        // 获取交易类型
+        $one                = isset($list[$id]) ? $list[$id] : [];
+        // 如果存在需要的字段
+        if( $field )        return isset($one[$field]) ? $one[$field] : null;
+        // 返回结果
+        return              $one;
+    }
+
+
+}

+ 7 - 1
app/Models/Traits/Score/BuyType.php

@@ -43,11 +43,17 @@ trait BuyType
                                         // 支付方式  方式名称
                                         'pay_type'      =>['1'=>['id'=>1,'name'=>'下单奖励']],
                                     ],'6'=>[
-                                        'id'            =>5,
+                                        'id'            =>6,
                                         // 类型名称
                                         'name'          =>'取消订单',
                                         // 支付方式  方式名称
                                         'pay_type'      =>['1'=>['id'=>1,'name'=>'取消订单']],
+                                    ],'7'=>[
+                                        'id'            =>7,
+                                        // 类型名称
+                                        'name'          =>'积分抽奖',
+                                        // 支付方式  方式名称
+                                        'pay_type'      =>['1'=>['id'=>1,'name'=>'抽奖消耗'],'2'=>['id'=>2,'name'=>'中奖积分']],
                                     ]];
 
     /**

+ 69 - 0
resources/views/admin/lottery_score/add.blade.php

@@ -0,0 +1,69 @@
+@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">活动Logo []</label>
+		<div id="logo">
+			<a id="logo-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat('')}}" height="100" />
+			</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="number" placeholder="新用户所需积分" min="1" name="need_score" value="" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">老用户所需积分</label>
+		<input class="form-control" required="required" type="number" placeholder="老用户所需积分" min="1" name="need_old_score" value="" />
+	</div>
+	<div class="form-group col-sm-5">
+		<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-5">
+		<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-6">
+		<label class="control-label">活动城市</label>
+		<select name="city_ids[]" class="form-control selectpicker" 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-6">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" 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

+ 70 - 0
resources/views/admin/lottery_score/edit.blade.php

@@ -0,0 +1,70 @@
+@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">活动Logo []</label>
+		<div id="logo">
+			<a id="logo-image" href="#" data-toggle="image" class="img-thumb">
+				<img src="{{path_compat($oldData['logo'])}}" height="100" />
+			</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="{{$oldData['name']}}" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">新用户所需积分</label>
+		<input class="form-control" required="required" type="number" placeholder="新用户所需积分" min="1" name="need_score" value="{{$oldData['need_score']}}" />
+	</div>
+	<div class="form-group col-sm-3">
+		<label class="control-label">老用户所需积分</label>
+		<input class="form-control" required="required" type="number" placeholder="老用户所需积分" min="1" name="need_old_score" value="{{$oldData['need_old_score']}}" />
+	</div>
+	<div class="form-group col-sm-5">
+		<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-5">
+		<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-6">
+		<label class="control-label">活动城市</label>
+		<select name="city_ids[]" class="form-control selectpicker" 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-6">
+		<label class="control-label">标签范围(标签存在延迟,请慎用)</label>
+		<select name="tag_scope[]" class="form-control selectpicker" 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

+ 89 - 0
resources/views/admin/lottery_score/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')
+
+@if(check_auth('admin/lottery_score/add'))
+	<div class="page-header">
+		<a href="{{url('admin/lottery_score/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-2 col-sm-2 col-xs-2" 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_score/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>									
+					</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> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
+							<td>
+								@if(check_auth('admin/lottery_score_reward/index'))
+								<a href="{{url('admin/lottery_score_reward/index?'.http_build_query(['lottery_id'=>$a['id']]))}}" class="btn btn-sm btn-primary" >奖品配置</a>
+								@endif
+								@if(check_auth('admin/lottery_score/edit'))
+								<a href="{{url('admin/lottery_score/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
+								@endif
+								@if(check_auth('admin/lottery_score/set_status'))
+									@if($a['status'])
+									<a data-url="{{url('admin/lottery_score/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_score/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

+ 88 - 0
resources/views/admin/lottery_score_record/index.blade.php

@@ -0,0 +1,88 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+
+@if(check_auth('admin/lottery_score_reward/add'))
+	<div class="page-header">
+		<a href="{{url('admin/lottery_score_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-2 col-sm-2 col-xs-2" 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-2 col-sm-2 col-xs-2" 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_score_reward/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>
+						<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_score_reward/edit'))
+								<a href="{{url('admin/lottery_score_reward/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
+								@endif
+								@if(check_auth('admin/lottery_score_reward/set_status'))
+									@if($a['status'])
+									<a data-url="{{url('admin/lottery_score_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_score_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

+ 53 - 0
resources/views/admin/lottery_score_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">奖品图片 []</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="number" 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_score_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">奖品图片 []</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" 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_score_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_score_reward/add'))
+	<div class="page-header">
+		<a href="{{url('admin/lottery_score_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-2 col-sm-2 col-xs-2" 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-2 col-sm-2 col-xs-2" 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_score_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_score_reward/edit'))
+								<a href="{{url('admin/lottery_score_reward/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
+								@endif
+								@if(check_auth('admin/lottery_score_reward/set_status'))
+									@if($a['status'])
+									<a data-url="{{url('admin/lottery_score_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_score_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

+ 10 - 2
routes/api.php

@@ -116,5 +116,13 @@ Route::any('banner/get_list',[\App\Http\Controllers\Api\Banner::class,'get_list'
 // 客服二维码
 Route::any('weiban_qrcode/get_qrcode',[\App\Http\Controllers\Api\WeiBanQrcode::class,'get_qrcode']);
 
-// 客服二维码
-Route::any('coupon/get_product',[\App\Http\Controllers\Api\Coupon::class,'get_product']);
+// 优惠券产品列表
+Route::any('coupon/get_product',[\App\Http\Controllers\Api\Coupon::class,'get_product']);
+
+/**
+ * 抽奖
+ */
+// 获取积分抽奖配置
+Route::any('lottery_score/get_detail',[\App\Http\Controllers\Api\Lottery\Score::class,'get_detail']);
+// 进行抽奖
+Route::any('lottery_score/get_reward',[\App\Http\Controllers\Api\Lottery\Score::class,'get_reward']);

+ 25 - 0
routes/web.php

@@ -323,5 +323,30 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     // 状态
     Route::any('weiban_qrcode/set_status',[App\Http\Controllers\Admin\WeibanQrcode::class,'set_status']);
     
+    /* 积分抽奖活动 */
+    // 列表
+    Route::any('lottery_score/index',[App\Http\Controllers\Admin\LotteryScore::class,'index']);
+    // 详情
+    Route::any('lottery_score/add',[App\Http\Controllers\Admin\LotteryScore::class,'add']);
+    // 详情
+    Route::any('lottery_score/edit',[App\Http\Controllers\Admin\LotteryScore::class,'edit']);
+    // 状态
+    Route::any('lottery_score/set_status',[App\Http\Controllers\Admin\LotteryScore::class,'set_status']);
+
+    /* 积分抽奖 */
+    // 列表
+    Route::any('lottery_score_reward/index',[App\Http\Controllers\Admin\LotteryScoreReward::class,'index']);
+    // 详情
+    Route::any('lottery_score_reward/add',[App\Http\Controllers\Admin\LotteryScoreReward::class,'add']);
+    // 详情
+    Route::any('lottery_score_reward/edit',[App\Http\Controllers\Admin\LotteryScoreReward::class,'edit']);
+    // 状态
+    Route::any('lottery_score_reward/set_status',[App\Http\Controllers\Admin\LotteryScoreReward::class,'set_status']);
+
+    /* 积分抽奖记录 */
+    // 列表
+    Route::any('lottery_score_record/index',[App\Http\Controllers\Admin\LotteryScoreRecord::class,'index']);
+    // 状态
+    Route::any('lottery_score_record/set_status',[App\Http\Controllers\Admin\LotteryScoreRecord::class,'set_status']);
 
 });