hrjy 3 years ago
parent
commit
82dc3a86f7

+ 5 - 8
app/api/controller/PublicController.php

@@ -289,24 +289,21 @@ class PublicController
      */
     public function store_list(Request $request)
     {
-        list($latitude, $longitude, $page, $limit, $cate_id, $name) = UtilService::getMore([
+        list($latitude, $longitude, $page, $limit, $cate_id, $name, $sales) = UtilService::getMore([
             ['latitude', ''],
             ['longitude', ''],
             ['page', 1],
             ['limit', 10],
             ['cate_id'],
-            ['name', '']
+            ['name', ''],
+            ['sales', '']
         ], $request, true);
-        $list = SystemStore::lst($latitude, $longitude, $page, $limit, $cate_id,$name);
+        $list = SystemStore::lst($latitude, $longitude, $page, $limit, $cate_id,$name, $sales);
         if (!$list){
             $list = [];
         } else{
             foreach ($list as &$item) {
-                $coupon = StoreCoupon::where('store_id', $item['id'])->column('id');
-                $item['coupon'] = StoreProduct::field('id,store_name,price,ot_price')->where('coupon', 'in',$coupon)->where('id', '>', 2)->select();
-                $id = StoreProduct::where('coupon', $item['id'])->where('id', '>', 2)->column('id');
-                $orderId = StoreOrderCartInfo::where('product_id', 'in',$id)->column('oid');
-                $item['count'] = count($orderId) > 0?StoreOrder::where('id', 'in',$orderId)->where('status', '>', 2)->count():0;
+               $item['count'] = $item['sales'];
             }
         }
         $data['list'] = $list;

+ 22 - 0
app/models/store/StoreOrder.php

@@ -783,11 +783,33 @@ class StoreOrder extends BaseModel
         UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
         //支付成功后
         self::operation($order['uid'], $orderId); // 发放优惠券
+        self::sales($order['id']);
         event('OrderPaySuccess', [$order, $formId]);
         $res = $res1 && $resPink && UserSpread::setSpreadSure($order['uid']) && User::backOrderBrokerage($order);
         return false !== $res;
     }
 
+    /**
+     * 增加销量
+     * @param $order_id
+     * @return void
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public static function sales($order_id)
+    {
+        $cart = StoreOrderCartInfo::where('oid',$order_id)->column('product_id');
+        $product = StoreProduct::where('id', 'in', $cart)->select();
+        foreach ($product as $item){
+            $coupon = StoreCoupon::where('id', 'in',$item['coupon'])->select();
+            foreach ($coupon as $v){
+                $store = SystemStore::where('id', $v['store_id'])->find();
+                $store['sales'] += 1;
+                $store->save();
+            }
+        }
+    }
 
     /**
      * 发放优惠券

+ 2 - 1
app/models/system/SystemStore.php

@@ -144,7 +144,7 @@ class SystemStore extends BaseModel
      * 门店列表
      * @return mixed
      */
-    public static function lst($latitude, $longitude, $page, $limit,$cate_id, $name)
+    public static function lst($latitude, $longitude, $page, $limit,$cate_id, $name, $sales)
     {
         $model = new self();
         $model = $model->where('is_del', 0);
@@ -153,6 +153,7 @@ class SystemStore extends BaseModel
             $model = $model->field(['*', self::distanceSql($latitude, $longitude)])->order('distance asc');
         }
         if ($name) $model = $model->where('name', 'like', '%'.$name.'%');
+        if ($sales) $model = $model->order('sales DESC');
         if ($cate_id) $model = $model->where('cate_id', $cate_id);
         $list = $model->page((int)$page, (int)$limit)
             ->select()