Эх сурвалжийг харах

Merge remote-tracking branch 'origin/jun' into liuxiangxin

liuxiangxin 5 сар өмнө
parent
commit
424520325a

+ 19 - 2
app/Http/Controllers/Admin/Business.php

@@ -2,6 +2,7 @@
 
 use App\Http\Requests\Admin\Business as Request;
 use App\Models\Business as Model;
+use App\Models\City;
 use Illuminate\Support\Carbon;
 
 /**
@@ -22,7 +23,7 @@ class Business extends Auth{
 	 * 列表页
 	 * 
 	 * */
-    public function index(Model $Model){
+    public function index(Model $Model,City $City){
  		// 接受参数
 		$code					= request('business_code','');
 		$phone					= request('phone','');
@@ -46,6 +47,19 @@ class Business extends Auth{
 			$value['business_code'] = $Model->idToCode($value['id']);
 			// 重组
 			$list[$key]			= $value;
+            if( $value['city_ids'] ) {
+                // 解析数组
+                $cityids			= explode(',',$value['city_ids']);
+                // 获取城市
+                foreach ($cityids as $kk=>$vv) 	{
+                    // 获取值
+                    $vv				= $City->getOne($vv,'name');
+                    // 获取城市名
+                    $cityids[$kk]	= $vv;
+                }
+                // 城市列表
+                $value['city_ids']	= implode('、',$cityids);
+            }
 		}
 		// 分配数据
 		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
@@ -58,7 +72,7 @@ class Business extends Auth{
 	 * 添加
 	 * 
 	 * */
-	public function add(Request $request,Model $Model){
+	public function add(Request $request,Model $Model,City $City){
 		if( request()->isMethod('post') ){
 			// 验证参数
 			$request->scene('add')->validate();
@@ -76,8 +90,11 @@ class Business extends Auth{
 			// 告知结果
 			return					json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
 		}
+        // 获取列表
+        $cityList					= $City->getCityList();
 		// 分配数据
 		$this->assign('crumbs','新增');
+        $this->assign('cityList',$cityList);
 		// 加载模板
 		return						$this->fetch(); 
 	}

+ 14 - 0
app/Http/Controllers/Admin/RecruitmentActivePrize.php

@@ -32,6 +32,17 @@ class RecruitmentActivePrize extends Auth{
         // 错误告知
         if( !$activeId )				return $this->error('缺失活动id');
         $oldData					= $Model->where(['active_id'=>$activeId])->first();
+        if($oldData){
+            if ($oldData['old_prize_type'] == 2){
+                $oldData['old_prize']          =   $Coupon->idToCode($oldData['old_prize']);
+            }
+            if ($oldData['new_prize_type'] == 2){
+                $oldData['new_prize']          =   $Coupon->idToCode($oldData['new_prize']);
+            }
+            if ($oldData['higher_prize_type'] == 2){
+                $oldData['higher_prize']       =   $Coupon->idToCode($oldData['higher_prize']);
+            }
+        }
 		// 修改
 		if(request()->isMethod('post')){
 			// 接收数据
@@ -48,6 +59,9 @@ class RecruitmentActivePrize extends Auth{
             if ($data['new_prize_type'] == 2){
                 $data['new_prize']          =   $Coupon->codeToId($data['new_prize']);
             }
+            if ($data['higher_prize_type'] == 2){
+                $data['higher_prize']       =   $Coupon->codeToId($data['higher_prize']);
+            }
             if ($oldData){
                 // 写入数据表
                 $result					= $Model->edit($oldData['id'],$data);

+ 2 - 0
app/Http/Controllers/Api/CustomCoupon.php

@@ -44,6 +44,7 @@ class CustomCoupon extends Api{
 		// 循环处理数据
 		foreach ($Paginator as $key => $value) {
 			$rebateScope			= [];
+            $productExclude         = [];
 			// 获取赠品列表
 			foreach ($rebates as $vv) {
 				// 获取优惠券的赠品
@@ -135,6 +136,7 @@ class CustomCoupon extends Api{
 		foreach ($list as $key => $value) {
 			// 适用范围
 			$productScope			= [];
+            $productExclude         = [];
 			// 如果是商品表,获取范围
 			if( $value['type_id'] == 1 ){
 				// 获取适用的商品范围

+ 1 - 0
app/Http/Controllers/Api/Recruitment.php

@@ -83,6 +83,7 @@ class Recruitment extends Api{
         if ($activeInfo){
             $activeInfo['start_time']       =   date('Y-m-d H:i:s',$activeInfo['start_time']);
             $activeInfo['end_time']         =   date('Y-m-d H:i:s',$activeInfo['end_time']);
+            $activeInfo['banner_img']       =   path_compat($activeInfo['banner_img']);
         }
         return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$activeInfo]);
     }

+ 146 - 124
app/Http/Controllers/Api/Wechat.php

@@ -90,116 +90,121 @@ class Wechat extends Api{
             ['end_time','>',$time],
             ['status','=',0],
         ];
-        $activeList                     = $RecruitmentActive::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get();
-        $activeInfo         =   [];
-        $data           =   [];
-        if ($activeList) {
-            foreach ($activeList as $active) {
-                $allowJoin = 0;
-                if ($active['tag_scope']) {
-                    // 解析数组
-                    $tag_scope = explode(',', $active['tag_scope']);
-                    // 标签范围限定时,默认不能参与
-                    // 判断标签是不是存在
-                    if ($tags) {
-                        foreach ($tags as $v) {
-                            // 标签范围内,允许参加
-                            if (in_array($v['name'], $tag_scope)) $allowJoin = 1;
+        try {
+            $activeList                     = $RecruitmentActive::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get();
+            $activeInfo         =   [];
+            $data           =   [];
+            if ($activeList) {
+                foreach ($activeList as $active) {
+                    $allowJoin = 0;
+                    if ($active['tag_scope']) {
+                        // 解析数组
+                        $tag_scope = explode(',', $active['tag_scope']);
+                        // 标签范围限定时,默认不能参与
+                        // 判断标签是不是存在
+                        if ($tags) {
+                            foreach ($tags as $v) {
+                                // 标签范围内,允许参加
+                                if (in_array($v['name'], $tag_scope)) $allowJoin = 1;
+                            }
                         }
+                    }else{
+                        $allowJoin = 1;
                     }
-                }else{
-                    $allowJoin = 1;
-                }
-                if ($active['tag_except']) {
-                    // 解析数组
-                    $tag_except = explode(',', $active['tag_except']);
-                    // 标签范围限定时,默认不能参与
-                    $allowJoin = 0;
-                    // 判断标签是不是存在
-                    if ($tags) {
-                        foreach ($tags as $v) {
-                            // 标签范围内,允许参加
-                            if (in_array($v['name'], $tag_except)) $allowJoin = 0;
+                    if ($active['tag_except']) {
+                        // 解析数组
+                        $tag_except = explode(',', $active['tag_except']);
+                        // 标签范围限定时,默认不能参与
+                        $allowJoin = 0;
+                        // 判断标签是不是存在
+                        if ($tags) {
+                            foreach ($tags as $v) {
+                                // 标签范围内,允许参加
+                                if (in_array($v['name'], $tag_except)) $allowJoin = 0;
+                            }
                         }
                     }
+                    if ($allowJoin) {
+                        $activeInfo         =   $active;
+                        break;
+                    }
                 }
-                if ($allowJoin) {
-                    $activeInfo         =   $active;
-                    break;
-                }
+            }else{
+                Log::error('recruitment','custom_uid:'.$uid.';暂无拉新活动:');
             }
-        }else{
-            Log::error('recruitment','custom_uid:'.$uid.';暂无拉新活动:');
-        }
-        if (!empty($activeInfo)){
-            $data['active_id']             =   $activeInfo['id'];
-            $data['old_uid']               =   $shareUid;
-            $data['new_uid']               =   $uid;
-            $data['insert_time']           =   $time;
-            $data['update_time']           =   $time;
-            //拉新记录
-            $recordId                      =   RecruitmentRecord::query()->insertGetId($data);
-            if ($recordId){
-                Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励:'.json_encode($activeInfo));
-                //查询活动奖励配置
-                $prizeInfo                  =   RecruitmentActivePrize::query()->where('active_id','=',$activeInfo['id'])->first();
-                if (!$prizeInfo) {
-                    Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励失败,无奖励配置:'.json_encode($prizeInfo));
-                    return false;
-                }
-                //赠送拉新奖励
-                if ($prizeInfo['old_prize']){
-                    switch ($prizeInfo['old_prize_type']) {
-                        case 1:
-                            //赠送老用户积分
-                            $res            =   $this->sendScore($shareUid,$prizeInfo['old_prize'],$recordId,1);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
-                            break;
-                        case 2:
-                            //赠送老用户优惠卷
-                            $res            =   $this->sendCoupon($shareUid,$prizeInfo['old_prize'],$recordId,1);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
-                            break;
+            if (!empty($activeInfo)){
+                $data['active_id']             =   $activeInfo['id'];
+                $data['old_uid']               =   $shareUid;
+                $data['new_uid']               =   $uid;
+                $data['insert_time']           =   $time;
+                $data['update_time']           =   $time;
+                //拉新记录
+                $recordId                      =   RecruitmentRecord::query()->insertGetId($data);
+                if ($recordId){
+                    Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励:'.json_encode($activeInfo));
+                    //查询活动奖励配置
+                    $prizeInfo                  =   RecruitmentActivePrize::query()->where('active_id','=',$activeInfo['id'])->first();
+                    if (!$prizeInfo) {
+                        Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励失败,无奖励配置:'.json_encode($prizeInfo));
+                        return false;
                     }
-                }
-                //赠送新用户奖励
-                if ($prizeInfo['new_prize']){
-                    switch ($prizeInfo['new_prize_type']) {
-                        case 1:
-                            //赠送老用户积分
-                            $res            =   $this->sendScore($uid,$prizeInfo['new_prize'],$recordId,2);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
-                            break;
-                        case 2:
-                            //赠送老用户优惠卷
-                            $res            =   $this->sendCoupon($uid,$prizeInfo['new_prize'],$recordId,2);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
-                            break;
+                    //赠送拉新奖励
+                    if ($prizeInfo['old_prize']){
+                        switch ($prizeInfo['old_prize_type']) {
+                            case 1:
+                                //赠送老用户积分
+                                $res            =   $this->sendScore($shareUid,$prizeInfo['old_prize'],$recordId,1);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
+                                break;
+                            case 2:
+                                //赠送老用户优惠卷
+                                $res            =   $this->sendCoupon($shareUid,$prizeInfo['old_prize'],$recordId,1);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
+                                break;
+                        }
                     }
-                }
-                //赠送上级奖励
-                if ($prizeInfo['higher_prize']){
-                    //查询上级用户
-                    $higherInfo         =   RecruitmentRecord::query()->where('new_uid','=',$shareUid)->first();
-                    if (!$higherInfo)   return true;
-                    switch ($prizeInfo['higher_prize_type']) {
-                        case 1:
-                            //赠送上级积分
-                            $res            =   $this->sendScore($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
-                            break;
-                        case 2:
-                            //赠送上级优惠卷
-                            $res            =   $this->sendCoupon($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
-                            if (!$res)      Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
-                            break;
+                    //赠送新用户奖励
+                    if ($prizeInfo['new_prize']){
+                        switch ($prizeInfo['new_prize_type']) {
+                            case 1:
+                                //赠送老用户积分
+                                $res            =   $this->sendScore($uid,$prizeInfo['new_prize'],$recordId,2);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
+                                break;
+                            case 2:
+                                //赠送老用户优惠卷
+                                $res            =   $this->sendCoupon($uid,$prizeInfo['new_prize'],$recordId,2);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
+                                break;
+                        }
                     }
+                    //赠送上级奖励
+                    if ($prizeInfo['higher_prize']){
+                        //查询上级用户
+                        $higherInfo         =   RecruitmentRecord::query()->where('new_uid','=',$shareUid)->first();
+                        if (!$higherInfo)   return true;
+                        switch ($prizeInfo['higher_prize_type']) {
+                            case 1:
+                                //赠送上级积分
+                                $res            =   $this->sendScore($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
+                                break;
+                            case 2:
+                                //赠送上级优惠卷
+                                $res            =   $this->sendCoupon($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
+                                if (!$res)      Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
+                                break;
+                        }
+                    }
+                }else{
+                    Log::error('recruitment','custom_uid:'.$uid.';拉新活动新增拉新记录失败:'.json_encode($data));
                 }
             }else{
-                Log::error('recruitment','custom_uid:'.$uid.';拉新活动新增拉新记录失败:'.json_encode($data));
+                Log::error('recruitment','custom_uid:'.$uid.';无拉新活动:'.json_encode($activeInfo));
             }
-        }else{
-            Log::error('recruitment','custom_uid:'.$uid.';无拉新活动:'.json_encode($activeInfo));
+        }catch (\Exception $e){
+            Log::error('recruitment','custom_uid:'.$uid.';拉新活动:'.json_encode($e));
+            return false;
         }
         return true;
     }
@@ -253,37 +258,54 @@ class Wechat extends Api{
         return true;
     }
     public function sendCoupon($uid,$prize,$recordId,$type=1){
+        Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送优惠卷:'.json_encode($prize));
         $time       =   time();
         $Coupon				                            = new \App\Models\Coupon();
         $CustomCoupon				                    = new \App\Models\CustomCoupon();
-        // 获取优惠券的可用时间
-        $couponData			                            = $Coupon->query()->where([['id','=',$prize],['status','=','0']])->first(['issue_total','status','exp_time']);
-        // 如果不存在数据,发送失败
-        if( !$couponData || $couponData['status'] )     return 0;
-        // 查询总共发放数量
-        $total                                          = $this->query()->where([['coupon_id','=',$prize]])->count();
-        // 数量超过的话。不发
-        if( $total >= $couponData['issue_total'] )      return 0;
-        // 时间转时间
-        $expTime			                            = $Coupon->getExpTime($couponData['exp_time']);
-        // 发送优惠券
-        $res                                            =  $CustomCoupon->add(['coupon_id'=>$prize,'custom_uid'=>$uid,'exp_time'=>$expTime]);
-        if (!$res)  return false;
-        //拉新奖励记录
-        $prizeRecordInfo            =   [
-            'recruitment_record_id'     =>  $recordId,
-            'custom_uid'                =>  $uid,
-            'type'                      =>  $type,
-            'prize_type'                =>  1,
-            'prize'                     =>  $prize,
-            'insert_time'               =>  $time,
-            'update_time'               =>  $time,
-        ];
-        $res        =   RecruitmentPrizeRecord::query()->insertGetId($prizeRecordInfo);
-        if (!$res){
-            Log::error('recruitment','奖励记录失败;record:'.json_encode($prizeRecordInfo));
+        try {
+            // 获取优惠券的可用时间
+            $couponData			                            = $Coupon->query()->where([['id','=',$prize],['status','=','0']])->first(['issue_total','status','exp_time']);
+            // 如果不存在数据,发送失败
+            if( !$couponData || $couponData['status'] ){
+                Log::error('recruitment','custom_uid:'.$uid.';优惠卷奖励不存在:'.json_encode($prize));
+                return false;
+
+            }
+            // 查询总共发放数量
+            $total                                          = $this->query()->where([['coupon_id','=',$prize]])->count();
+            // 数量超过的话。不发
+            if( $total >= $couponData['issue_total'] ) {
+                Log::error('recruitment','custom_uid:'.$uid.';优惠卷奖励超发:'.json_encode($prize));
+                return false;
+            }
+            // 时间转时间
+            $expTime			                            = $Coupon->getExpTime($couponData['exp_time']);
+            // 发送优惠券
+            $res                                            =  $CustomCoupon->add(['coupon_id'=>$prize,'custom_uid'=>$uid,'exp_time'=>$expTime]);
+            if (!$res){
+                Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送优惠卷奖励失败:'.json_encode($prize));
+                return false;
+            }
+            //拉新奖励记录
+            $prizeRecordInfo            =   [
+                'recruitment_record_id'     =>  $recordId,
+                'custom_uid'                =>  $uid,
+                'type'                      =>  $type,
+                'prize_type'                =>  2,
+                'prize'                     =>  $prize,
+                'insert_time'               =>  $time,
+                'update_time'               =>  $time,
+            ];
+            $res        =   RecruitmentPrizeRecord::query()->insertGetId($prizeRecordInfo);
+            if (!$res){
+                Log::error('recruitment','奖励记录失败;record:'.json_encode($prizeRecordInfo));
+                return false;
+            }
+        }catch (\Exception $e){
+            Log::error('recruitment','奖励优惠卷失败;record:'.json_encode($e));
             return false;
         }
+
         return true;
     }
 }

+ 6 - 0
resources/views/admin/business/index.blade.php

@@ -41,6 +41,9 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						<th>商店状态</th>
 						<th>商店名称</th>
 						<th>联系方式</th>
+						<th>城市</th>
+						<th>详细地址</th>
+						<th>上级代表</th>
 						<th>简介说明</th>
 						<th>创建时间</th>
 						<th>操作</th>									
@@ -54,6 +57,9 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							<td>{{$a['status']?'禁用':'正常'}}</td>
 							<td>{{$a['name']}}</td>
 							<td>{{$a['phone']}}</td>
+							<td>{{$a['city_ids']}}</td>
+							<td>{{$a['address']}}</td>
+							<td>{{$a['leader_uid']}}</td>
 							<td>{{$a['desc']}}</td>
 							<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
 							<td>