wesmiler 1 gadu atpakaļ
vecāks
revīzija
41c3173438

+ 1 - 1
app/Console/Commands/SocketServer.php

@@ -165,7 +165,7 @@ class SocketServer extends Command
                         $this->sendMsg($frameId, ['success' => false, 'message' => '发送消息内容违规']);
                         return false;
                     }
-                    
+
                     $data = [
                         'from_user_id' => $fromUid,
                         'to_user_id' => $toUid,

+ 29 - 1
app/Services/Api/CouponService.php

@@ -17,6 +17,7 @@ use App\Models\MemberModel;
 use App\Models\MerchantModel;
 use App\Services\BaseService;
 use App\Services\ConfigService;
+use Illuminate\Support\Facades\DB;
 
 /**
  * 优惠券-服务类
@@ -74,7 +75,9 @@ class CouponService extends BaseService
 
                 $merchId = isset($params['merch_id'])? $params['merch_id'] : 0;
                 if($merchId){
-                    $query->where('merch_id','=', $merchId);
+                    $query->where(function ($query) use($merchId){
+                        $query->where('merch_id','=', $merchId)->orWhereRaw('FIND_IN_SET(?,apply_merch_ids)',[$merchId]);
+                    });
                 }
 
                 $userId = isset($params['user_id'])? $params['user_id'] : 0;
@@ -180,6 +183,31 @@ class CouponService extends BaseService
    }
 
     /**
+     * 获取店铺可领取优惠券
+     * @param $merchId
+     * @param int $total
+     * @return mixed
+     */
+   public function getCountByMerch($merchId, $total=0)
+   {
+       return $this->model->where(['status'=>1,'mark'=>1])
+           ->where(function($query) use ($merchId, $total){
+               $query->where(function ($query) use($merchId){
+                   $query->where('merch_id','=', $merchId)->orWhereRaw('FIND_IN_SET(?,apply_merch_ids)',[$merchId]);
+               });
+
+               if($total>0){
+                   $query->where(function($query) use($total){
+                       $query->where('min_price','<=', $total)->orWhere('min_price','=',0);
+                   });
+               }
+
+               $query->where('start_time','<=', time())
+                   ->where('end_time','>=', time());
+           })->count('id');
+   }
+
+    /**
      * 状态
      * @return bool
      */

+ 1 - 0
app/Services/Api/GoodsService.php

@@ -426,6 +426,7 @@ class GoodsService extends BaseService
             }
 
             $info['service_type'] = $info['service_type']? $info['service_type'] : [2,3];
+            $info['coupon_num'] = CouponService::make()->getCountByMerch($info['merch_id'], $info['price']);
 
             $info['service_status'] = 2;
             $info['service_time'] = isset($info['service_time']) && $info['service_time']? $info['service_time']:'08点~22点';