APPLE преди 3 години
родител
ревизия
1f4d10f550

+ 3 - 3
app/Http/Controllers/Api/v1/GoodsController.php

@@ -20,7 +20,7 @@ class GoodsController extends webApp
     {
         $params = request()->all();
         $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
-//        $params['shop_id'] = 3;
+
         $params['shop_id'] = $this->shopId;
         $params['not_user_id'] = $this->userId;
         $params['is_trade'] = 2;
@@ -106,8 +106,8 @@ class GoodsController extends webApp
     public function change()
     {
         $params = request()->all();
-        $goodsId = isset($params['id'])? $params['id'] : 0;
-        if(GoodsService::make()->change($goodsId)){
+        $goodsIds = isset($params['ids'])? $params['ids'] : 0;
+        if(GoodsService::make()->change($goodsIds)){
             return message(GoodsService::make()->getError(), true);
         }else{
             return message(GoodsService::make()->getError(), false);

+ 2 - 1
app/Http/Controllers/Api/webApp.php

@@ -116,9 +116,10 @@ class webApp extends BaseController
             $userInfo = $memberModel->where(['id'=> $userId])
                 ->select(['id','nickname','mobile','code','parent_id','login_shop_id'])
                 ->first();
+            $userInfo = $userInfo? $userInfo->toArray() : [];
             $this->userInfo = $userInfo;
             $this->shopId = isset($userInfo['login_shop_id'])? $userInfo['login_shop_id'] : 0;
-            RedisService::set("auths:info:{$userId}", $this->userInfo, 4*24*3600);
+            RedisService::set("auths:info:{$userId}", $userInfo, 4*24*3600);
         }
 
     }

+ 23 - 16
app/Services/Common/GoodsService.php

@@ -81,6 +81,7 @@ class GoodsService extends BaseService
             $where['a.user_id'] = $userId;
         }
 
+
         $type = isset($params['type']) ? $params['type'] : 0;
         $list = $this->model->from('goods as a')
             ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
@@ -92,23 +93,28 @@ class GoodsService extends BaseService
                 }else if($type == 2){
                     $query->where(['a.confirm_status'=> 1, 'a.status'=> 1,'a.is_trade'=>2]);
                 }else if($type == 3){
-                    $query->where(['','a.confirm_status'=> 1, 'a.status'=> 1,'a.is_trade'=>2]);
+                    $query->where(['a.confirm_status'=> 1, 'a.status'=> 1,'a.is_trade'=>2]);
                 }
             })
             ->where(function ($query) use ($params) {
                 $keyword = isset($params['keyword']) ? $params['keyword'] : '';
                 if ($keyword) {
-                    $query->orWhere('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%")->orWhere('c.name', 'like', "%{$keyword}%")->orWhere('c.code', 'like', "%{$keyword}%")->where('a.goods_name', 'like', "%{$keyword}%");
+                    $searchType = isset($params['search_type'])? $params['search_type'] : 0;
+                    if($searchType == 1){
+                        $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%")->orWhere('a.goods_name', 'like', "%{$keyword}%");
+                    }else{
+                        $query->where('c.name', 'like', "%{$keyword}%")->orWhere('c.code', 'like', "%{$keyword}%")->orWhere('a.goods_name', 'like', "%{$keyword}%");
+                    }
                 }
 
                 $keyword1 = isset($params['keyword1']) ? $params['keyword1'] : '';
                 if ($keyword1) {
-                    $query->orWhere('a.code', 'like', "%{$keyword1}%");
+                    $query->where('a.code', 'like', "%{$keyword1}%");
                 }
 
                 $username = isset($params['username']) ? $params['username'] : '';
                 if ($username) {
-                    $query->orWhere('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%");
+                    $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%");
                 }
             })
             ->where(function ($query) use ($params) {
@@ -119,7 +125,7 @@ class GoodsService extends BaseService
             })
             ->where(function ($query) use ($params) {
                 $notUserId = isset($params['not_user_id']) ? $params['not_user_id'] : 0;
-                if ($notUserId) {
+                if ($notUserId>0) {
                     $query->whereNotIn('a.user_id', [$notUserId]);
                 }
             })
@@ -496,23 +502,22 @@ class GoodsService extends BaseService
      * 转场
      * @param $goodsId
      */
-    public function change($goodsId)
+    public function change($goodsIds)
     {
         $params = request()->all();
-        $changeShopId = isset($params['change_shop_id']) ? $params['change_shop_id'] : 0;
-        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
-        if (empty($goods)) {
-            $this->error = 2061;
+        $changeShopCode = isset($params['change_shop_code']) ? $params['change_shop_code'] : '';
+        $shopInfo = ShopModel::where(['code' => $changeShopCode, 'mark' => 1])->first();
+        if (empty($shopInfo)) {
+            $this->error = 2062;
             return false;
         }
 
-        $shopInfo = ShopModel::where(['id' => $changeShopId, 'mark' => 1])->first();
-        if (empty($shopInfo)) {
-            $this->error = 2062;
+        if (empty($goodsIds)) {
+            $this->error = 2404;
             return false;
         }
 
-        if ($this->model->where(['id' => $goodsId])->update(['shop_id' => $changeShopId, 'update_time' => time(), 'remark' => '店长转场'])) {
+        if ($this->model->whereIn('id', $goodsIds)->update(['shop_id' => $shopInfo['id'], 'update_time' => time(), 'remark' => '店长转场'])) {
             $this->error = 1002;
             return true;
         }
@@ -620,7 +625,7 @@ class GoodsService extends BaseService
         $cacheKey = "caches:goods:Count:{$userId}";
         $data = RedisService::get($cacheKey);
         if($data){
-           return $data;
+            return $data;
         }
 
         $data = $this->model->where(['user_id'=>$userId,'status'=>1,'mark'=>1])->count();
@@ -646,13 +651,15 @@ class GoodsService extends BaseService
 
         $result = parent::delete(); // TODO: Change the autogenerated stub
         $code = isset($result['success'])? $result['success'] : '';
+        var_dump($ids);
+        var_dump($result);
         if(!$code){
             DB::rollBack();
             return $result;
         }
 
         // 删除交易记录
-        if(!TradeModel::whereIn('goods_id', $ids)->update(['mark'=>0,'remark'=>'删除商品同步删除','update_time'=>time()])){
+        if(TradeModel::whereIn('goods_id', $ids)->count() && !TradeModel::whereIn('goods_id', $ids)->update(['mark'=>0,'remark'=>'删除商品同步删除','update_time'=>time()])){
             DB::rollBack();
             return message('删除商品交易记录失败', false);
         }

+ 16 - 13
app/Services/Common/MemberService.php

@@ -294,7 +294,7 @@ class MemberService extends BaseService
         // JWT生成token
         $jwt = new Jwt('jwt_app');
         $token = $jwt->getToken($info['id']);
-        RedisService::set("stores:auths:info:{$info['id']}", $info, 5, 10);
+        RedisService::set("stores:auths:info:{$info['id']}", $info->toArray(), 5, 10);
 
         // 登录
         $updateData = ['login_time' => time(),'login_shop_id'=> $shopId,'login_count'=>$info['login_count']+1, 'login_ip' => get_client_ip()];
@@ -529,12 +529,12 @@ class MemberService extends BaseService
         $parentId = getter($param, "parent_id");
         $userId = getter($param, "user_id");
         $datas = $this->model->where(function($query) use($parentId){
-                if($parentId){
-                    $query->where(['id'=> $parentId,'mark'=>1]);
-                }else{
-                    $query->where(['status'=> 1,'mark'=>1]);
-                }
-            })
+            if($parentId){
+                $query->where(['id'=> $parentId,'mark'=>1]);
+            }else{
+                $query->where(['status'=> 1,'mark'=>1]);
+            }
+        })
             ->where(function($query) use($userId){
                 if($userId){
                     $query->whereNotIn('id', [$userId]);
@@ -600,12 +600,12 @@ class MemberService extends BaseService
         $pid = 0;
         if($keyword){
             $data = $this->model->where(function($query) use($keyword){
-                        $query->where('nickname','like',"{$keyword}%")->orWhere('mobile','like',"{$keyword}%");
-                    })
-                    ->where(['status'=>1,'mark'=>1])
-                    ->orderBy('parent_id','asc')
-                    ->select(['id','parent_id','nickname','mobile','username'])
-                    ->first();
+                $query->where('nickname','like',"{$keyword}%")->orWhere('mobile','like',"{$keyword}%");
+            })
+                ->where(['status'=>1,'mark'=>1])
+                ->orderBy('parent_id','asc')
+                ->select(['id','parent_id','nickname','mobile','username'])
+                ->first();
             $nickname = isset($data['nickname'])? $data['nickname'] : '';
             $username = isset($data['username'])? $data['username'] : '';
             $mobile = isset($data['mobile'])? $data['mobile'] : '';
@@ -647,6 +647,9 @@ class MemberService extends BaseService
             $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
         }
 
+        if(!isset($data['merits_time']) && empty($data['merits_time'])){
+            $data['merits_time'] = date('Y-m-d', time() - 2*86400);
+        }
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 

+ 41 - 25
app/Services/Common/TradeService.php

@@ -83,10 +83,6 @@ class TradeService extends BaseService
             $where['a.is_appeal'] = $isAppeal;
         }
 
-        if ($status > 0 && !$isAppeal) {
-            $where['a.status'] = $status;
-        }
-
         if ($goodsStatus > 0) {
             $where['g.status'] = $goodsStatus;
         }
@@ -97,13 +93,14 @@ class TradeService extends BaseService
             ->leftJoin('shop as s', 's.id', '=', 'g.shop_id')
             ->where($where)
             ->where('a.status', '>', 0)
-            ->where(function ($query) use ($userId, $status) {
-//                if($status == 0){
-//                    $query->whereNotIn('a.sell_uid',[$userId]);
-//                }
-//                else if($status == 2){
-//                    $query->whereNotIn('a.user_id',[$userId]);
-//                }
+            ->where(function ($query) use ($type, $status, $isAppeal) {
+                if($type == 1 && $status == 2){
+                    $query->whereIn('a.status',[1,2,3])->orWhere(function($query) {
+                        $query->where(['a.status'=>4])->where('a.is_sell','<=', 1);
+                    });
+                }else if($status>0 && !$isAppeal){
+                    $query->where(['a.status'=> $status]);
+                }
             })
             ->where(function ($query) use ($params) {
                 $keyword = isset($params['keyword']) ? $params['keyword'] : '';
@@ -123,6 +120,7 @@ class TradeService extends BaseService
             ->where(function ($query) use ($type, $userId, $sellUid, $status) {
 
                 if ($type == 1) {
+                    $query->whereIn('a.status',[1,2,3,4]);
                     if ($status == 0) {
                         $query->where(['a.user_id' => $userId, 'a.is_out' => 0]);
                         $query->whereNotIn('a.sell_uid', [$userId]);
@@ -132,6 +130,8 @@ class TradeService extends BaseService
                     } else {
                         $query->where(['a.user_id' => $userId, 'a.is_out' => 0]);
                     }
+                } else if($type == 3){
+                    $query->whereIn('a.status',[1,2,3,4]);
                 } else {
                     if ($userId) {
                         $query->where(['a.user_id' => $userId, 'a.is_out' => 0]);
@@ -139,20 +139,13 @@ class TradeService extends BaseService
                         $query->where('a.sell_uid', '=', $sellUid);
                     }
                 }
-                /*if ($sellUid && $userId) {
-                    $query->where('a.user_id', $userId)->orWhere(function($query) use($sellUid){
-                        $query->where('a.sell_uid', $sellUid)->whereIn('a.status', [1,2]);
-                    });
-                }else if($userId){
-                    $query->where('a.user_id', '=', $userId);
-                }else if($sellUid){
-                    $query->where('a.sell_uid', '=', $sellUid);
-                }*/
             })
             ->select(['a.*', 'b.nickname', 'b.mobile as buy_mobile', 's.name as shop_name', 's.code as shop_code', 'c.nickname as sell_nickname', 'c.mobile as sell_mobile', 'g.goods_name', 'g.code', 'g.thumb']);
 
         // 店长排序
-        if ($type == 3) {
+        if ($type == 1) {
+            $model = $model->orderBy('a.status', 'asc');
+        } else if ($type == 3) {
             $model = $model->orderBy('a.status', 'asc')->orderBy('a.is_sell', 'asc');
         }
         $model = $model->orderBy('s.id', 'asc')
@@ -925,6 +918,13 @@ class TradeService extends BaseService
             return false;
         }
 
+        // 卖家收款账号
+//        $bankInfo = MemberBankService::make()->getBindInfo($info['user_id']);
+//        if (empty($bankInfo)) {
+//            $this->error = 2060;
+//            return false;
+//        }
+
         if ($this->model->where(['id' => $id, 'mark' => 1])->update(['pay_time' => time(), 'pay_img' => $payImg, 'status' => 2, 'update_time' => time()])) {
             $this->error = 2046;
             return true;
@@ -1443,13 +1443,22 @@ class TradeService extends BaseService
             return false;
         }
 
-        if ($this->model->where(['id' => $id])->update(['status' => 5, 'update_time' => time()])) {
-            $this->error = 2088;
-            return true;
-        } else {
+        DB::beginTransaction();
+        if (!$this->model->where(['id' => $id])->update(['status' => 5,'remark'=>'店长取消订单:'.date('Y-m-d H:i:s'), 'update_time' => time()])) {
+            DB::rollBack();
+            $this->error = 2089;
+            return false;
+        }
+
+        if(!GoodsModel::where(['id'=> $info['goods_id'],'mark'=>1])->update(['status'=>1,'is_trade'=>2,'confirm_status'=>1,'remark'=>'店长取消订单'])){
+            DB::rollBack();
             $this->error = 2089;
             return false;
         }
+
+        DB::commit();
+        $this->error = 2088;
+        return true;
     }
 
     /**
@@ -1466,6 +1475,13 @@ class TradeService extends BaseService
             return false;
         }
 
+        // 取消订单
+        $this->model->where('create_time', '<', strtotime(date('Y-m-d')))
+            ->where('create_time', '<', time() - 7200)->where(['mark' => 1])
+            ->where('status','<',4)
+            ->update(['mark'=>0,'remark'=>'订单未付款取消']);
+
+        // 清除订单
         $clearDay = strtotime(date('Y-m-d')) - $day * 86400;
         $count = $this->model->where('create_time', '<', $clearDay)->count();
         if ($count <= 0) {