From 637047894ef79b766844ca60567d32047461c9c1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 18 Nov 2023 13:42:08 +0800 Subject: [PATCH 01/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/SpuRepository.php | 2 +- app/listener/OrderTake.php | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index f77195f7..27c9918c 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -90,7 +90,7 @@ class SpuRepository extends BaseRepository 'keyword' => $param['keyword'] ?? '', 'image' => $param['image'], 'price' => $param['price'], - 'status' => 0, + 'status' => $param['status']??0, 'rank' => $param['rank'] ?? 0, 'temp_id' => $param['temp_id'], 'sort' => $param['sort'] ?? 0, diff --git a/app/listener/OrderTake.php b/app/listener/OrderTake.php index ad18a354..7fafc292 100644 --- a/app/listener/OrderTake.php +++ b/app/listener/OrderTake.php @@ -39,12 +39,7 @@ class OrderTake $product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select(); foreach ($product_arr as $k => $v) { $this->import($v, $order); - - // app(ProductRepository::class)->create($find, 0); } - // $productId = $this->import($params['order_product_id'], request()->userInfo()); - // $product = $this->get($productId); - // $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find(); } } catch (\Exception $e) { Log::error($e->getMessage() . 'lien:' . $e->getLine()); @@ -73,6 +68,7 @@ class OrderTake Log::error('采购导入商品:已经导入过该规格了'); return false; } + /**查询原始商品的规格 */ $attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) ->where('unique', $product['product_sku']) ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') @@ -81,18 +77,21 @@ class OrderTake }) ->find(); $find['attr'] = []; + $is_update=false; if ($attrValue['detail']) { foreach ($attrValue['detail'] as $kk => $vv) { - - $attr_values = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) - ->value('attr_values'); - if ($attr_values) { + /**查询当前规格是否存在 */ + $attr_values_find = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) + ->find(); + if ($attr_values_find) { + $attr_values= $attr_values_find['attr_values']; $attr_values = explode('-!-', $attr_values); if (!in_array($vv, $attr_values)) { $attr_values[] = $vv; $attr_values = implode('-!-', $attr_values); Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); } + $is_update=true; } else { $attr_values = $vv; @@ -105,13 +104,20 @@ class OrderTake } } } - $attrValue['stock'] = $product['refund_num']; - $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); - $attrValue['unique'] = $unique; - $attrValue['detail'] = json_encode($attrValue['detail']); - $attrValue['product_id'] = $exist['product_id']; - $attrValue['mer_id'] = $mer_id; - Db::name('store_product_attr_value')->insert($attrValue); + /**规格新增还是更新 */ + if($is_update==false){ + $attrValue['stock'] = $product['refund_num']; + $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); + $attrValue['unique'] = $unique; + $attrValue['detail'] = json_encode($attrValue['detail']); + $attrValue['product_id'] = $exist['product_id']; + $attrValue['mer_id'] = $mer_id; + Db::name('store_product_attr_value')->insert($attrValue); + }else{ + Db::name('store_product_attr_value')->where(['unique'=>$attr_values_find['unique'],'product_id', + $attr_values_find['product_id'],'mer_id'=>$mer_id,])->update(['stock'=>$product['refund_num']+$attr_values_find['stock']]); + } + Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]); $data = [ 'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'], From f363de8995890fd5178516156238638df7b0aa4f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 10:35:27 +0800 Subject: [PATCH 02/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=8D=E5=85=BB?= =?UTF-8?q?=E6=AE=96=E6=88=B7=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Statistics.php | 63 ++++++++++++++++++++++++------- route/api.php | 1 + 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/controller/api/Statistics.php b/app/controller/api/Statistics.php index e94d16d3..85f6bbb1 100644 --- a/app/controller/api/Statistics.php +++ b/app/controller/api/Statistics.php @@ -109,11 +109,11 @@ class Statistics extends BaseController if (isset($parmas['keyword']) && $parmas['keyword'] != '') { $where[] = ['store_name', 'like', '%' . $parmas['keyword'] . '%']; } - $count=Db::name('store_product')->where($where)->count(); + $count = Db::name('store_product')->where($where)->count(); $list = Db::name('store_product')->where($where)->page($parmas['page']) ->field('product_id,store_name,image,price') ->limit(10)->select(); - return app('json')->success(['page' => $parmas['page'], 'data' => $list,'count'=>$count]); + return app('json')->success(['page' => $parmas['page'], 'data' => $list, 'count' => $count]); } /** @@ -149,7 +149,7 @@ class Statistics extends BaseController if (!isset($parmas['goods_id']) || $parmas['goods_id'] == '') { return app('json')->fail('goods_id:格式错误'); } - $mer_id=Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id'); + $mer_id = Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id'); $where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; $where[] = ['p.product_id', 'in', explode(',', $parmas['goods_id'])]; $where[] = ['p.is_refund', '=', 0]; @@ -231,7 +231,7 @@ class Statistics extends BaseController // return app('json')->fail('type:格式错误'); // } $area[] = ['street_id', 'in', explode(',', $parmas['responsible_area'])]; - $area[] = ['type_id', '=',17]; + $area[] = ['type_id', '=', 17]; $merchant = Db::name('merchant')->where($area)->column('mer_id'); if (!$merchant) { @@ -262,17 +262,52 @@ class Statistics extends BaseController if (!isset($parmas['phone']) || $parmas['phone'] == '') { return app('json')->fail('phone:格式错误'); } - $user_id= Db::name('user')->where('account',$parmas['phone'])->value('uid'); - if(!$user_id){ + $user_id = Db::name('user')->where('account', $parmas['phone'])->value('uid'); + if (!$user_id) { return app('json')->fail('查询的手机号用户不存在'); } - $where[]=['create_time','between time',[date("Y-m-d H:i:s",$parmas['start_time']),date("Y-m-d H:i:s",$parmas['end_time'])]]; - $where[]=['paid','=',1]; - $where[]=['status','<>',-1]; - $where[]=['uid','=',$user_id]; - $count=Db::name('store_order') - ->where($where) - ->sum('pay_price'); - return app('json')->success(['trade_amount'=>$count]); + $where[] = ['create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; + $where[] = ['paid', '=', 1]; + $where[] = ['status', '<>', -1]; + $where[] = ['uid', '=', $user_id]; + $count = Db::name('store_order') + ->where($where) + ->sum('pay_price'); + return app('json')->success(['trade_amount' => $count]); + } + + /** + * 查询镇农科公司负责片区内的种养殖商户和供应链商户交易额 + *暂无种养殖商户分类 + */ + public function SupplyChainVillageBreedingPriceCount() + { + $parmas = $this->request->param(); + + if (!isset($parmas['start_time']) || $parmas['start_time'] == '') { + return app('json')->fail('start_time:格式错误'); } + if (!isset($parmas['end_time']) || $parmas['end_time'] == '') { + return app('json')->fail('end_time:格式错误'); + } + if (!isset($parmas['village']) || $parmas['village'] == '') { + return app('json')->fail('village:格式错误'); + } + $village_id = Db::name('geo_village')->where('village_code', $parmas['village'])->value('village_id'); + $merchant_category_id = Db::name('merchant_category')->where('code', 'zhongyangzhi')->value('merchant_category_id'); + $area[] = ['village_id', '=', $village_id]; + $area[] = ['category_id', '=', $merchant_category_id]; + + $merchant = Db::name('merchant')->where($area)->column('mer_id'); + if (!$merchant) { + return app('json')->fail('查询商户为空'); + } + $where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]]; + $where[] = ['p.is_refund', '=', 0]; + $count = Db::name('store_order_product')->alias('p') + ->where($where) + ->join('store_order o', 'o.mer_id in (' . implode(',', $merchant) . ') and o.paid=1 and o.is_del=0') + ->sum('p.total_price'); + return app('json')->success(['trade_amount' => $count]); + } } diff --git a/route/api.php b/route/api.php index e47ccf46..8856b174 100644 --- a/route/api.php +++ b/route/api.php @@ -704,6 +704,7 @@ Route::group('api/', function () { Route::get('supply_chain_product_price_count', '/SupplyChainProductPriceCount'); Route::get('supply_chain_street_product_price_count', '/SupplyChainStreetProductPriceCount'); Route::get('supply_chain_breeding_street_product_count', '/SupplyChainBreedingStreetProductCount'); + Route::get('supply_chain_village_breeding_price_count', '/SupplyChainVillageBreedingPriceCount'); Route::get('store_order_user_trade_amount', '/StoreOrderUserTradeAmount'); })->prefix('api.Statistics'); From ee92e1f33c1d599be8473be22a9d297454dd0424 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 13:42:46 +0800 Subject: [PATCH 03/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/merchant/Merchant.php | 3 +- app/controller/api/server/StoreProduct.php | 50 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index 96facf9f..aadfd407 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -244,7 +244,8 @@ class Merchant extends BaseController if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $admins=$this->request->adminInfo(); - if($admins['admin_id']!=1){ + $admin_arr=explode(',',env('MERCHANT_Arr')); + if($admins['admin_id']!=1 && !in_array($admins['roles'],$admin_arr)){ $adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2); if(!$adminInfo){ $pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT); diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 24ba3c60..8c2871d7 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -58,14 +58,14 @@ class StoreProduct extends BaseController public function lst($merId) { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id', 'keyword', ['type',20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels',['order','sort']]); + $where = $this->request->params(['cate_id', 'keyword', ['type', 20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels', ['order', 'sort']]); $merchant = app()->make(MerchantRepository::class)->get($merId); - $typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code'); + $typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code'); // if ($merchant['type_id']==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 - }else{ - $product_type=0;//普通商品 + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 + } else { + $product_type = 0; //普通商品 } $where = array_merge($where, $this->repository->switchType($where['type'], $merId, $product_type)); return app('json')->success($this->repository->getList($merId, $where, $page, $limit)); @@ -82,21 +82,26 @@ class StoreProduct extends BaseController public function create($merId, StoreProductValidate $validate) { $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId); + $data = $this->repository->checkParams($res, $merId); $data['mer_id'] = $merId; $data['is_gift_bag'] = 0; $merchant = app()->make(MerchantRepository::class)->get($merId); $data['status'] = $merchant->is_audit ? 0 : 1; $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; $data['rate'] = 3; - $typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code'); - if ($merchant['type_id']==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 - }else{ - $product_type=0;//普通商品 + $typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code'); + $product_type = 0; //普通商品 + if ($merchant['type_id'] == 12) { + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 + } } $productId = $this->repository->create($data, $product_type, 1); + if ($productId) { + return app('json')->success('添加成功'); + } else { + return app('json')->fail('添加失败'); + } // $unique = Db::name('store_product_attr_value')->where('product_id', $productId)->value('unique'); // if (!empty($unique) && $stockNum > 0) { // $this->repository->stockIn($merId, [ @@ -104,8 +109,6 @@ class StoreProduct extends BaseController // 'unique' => $unique, // 'number' => $stockNum, // ]); - } - return app('json')->success('添加成功'); } /** @@ -120,7 +123,7 @@ class StoreProduct extends BaseController public function update($merId, $id, StoreProductValidate $validate) { $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId,$id); + $data = $this->repository->checkParams($res, $merId, $id); $merchant = app()->make(MerchantRepository::class)->get($merId); if (!$this->repository->merExists($merId, $id)) @@ -167,7 +170,7 @@ class StoreProduct extends BaseController $status = $this->request->param('status', 0) == 1 ? 1 : 0; if (!$this->repository->merExists($merId, $id)) return app('json')->fail('数据不存在'); - $this->repository->switchShow($id,$status, 'is_show',$merId); + $this->repository->switchShow($id, $status, 'is_show', $merId); return app('json')->success('修改成功'); } @@ -194,9 +197,9 @@ class StoreProduct extends BaseController $data['extension_status'] = systemConfig('extension_status'); $data['integral_status'] = 0; $data['integral_rate'] = 0; - if(systemConfig('integral_status') && merchantConfig($merId,'mer_integral_status')) { + if (systemConfig('integral_status') && merchantConfig($merId, 'mer_integral_status')) { $data['integral_status'] = 1; - $data['integral_rate'] = merchantConfig($merId,'mer_integral_rate'); + $data['integral_rate'] = merchantConfig($merId, 'mer_integral_rate'); } $merchant = app()->make(MerchantRepository::class)->get($merId); $data['delivery_way'] = $merchant->delivery_way; @@ -239,15 +242,14 @@ class StoreProduct extends BaseController public function stockIn() { $params = $this->request->param(); - if($params['unique']==''){ + if ($params['unique'] == '') { return app('json')->fail('多规格编号不能为空'); } - $res=$this->repository->stockIn($this->merId, $params); - if($res){ + $res = $this->repository->stockIn($this->merId, $params); + if ($res) { return app('json')->success('入库成功'); - }else{ + } else { return app('json')->fail('入库失败'); } } - } From fbb25484a3ef149e43953f521e4b5f5e6ae6787c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 15:23:30 +0800 Subject: [PATCH 04/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/system/merchant/Merchant.php | 8 +++++++- app/controller/api/Statistics.php | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index aadfd407..4b79b5cd 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -245,7 +245,13 @@ class Merchant extends BaseController return app('json')->fail('数据不存在'); $admins=$this->request->adminInfo(); $admin_arr=explode(',',env('MERCHANT_Arr')); - if($admins['admin_id']!=1 && !in_array($admins['roles'],$admin_arr)){ + $is_true=false; + foreach ($admins['roles'] as $k=>$v){ + if(in_array($v,$admin_arr)){ + $is_true=true; + } + } + if($admins['admin_id']!=1 && $is_true==false){ $adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2); if(!$adminInfo){ $pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT); diff --git a/app/controller/api/Statistics.php b/app/controller/api/Statistics.php index 85f6bbb1..b4dcca17 100644 --- a/app/controller/api/Statistics.php +++ b/app/controller/api/Statistics.php @@ -262,7 +262,8 @@ class Statistics extends BaseController if (!isset($parmas['phone']) || $parmas['phone'] == '') { return app('json')->fail('phone:格式错误'); } - $user_id = Db::name('user')->where('account', $parmas['phone'])->value('uid'); + $account[] = ['account', 'in', explode(',', $parmas['phone'])]; + $user_id = Db::name('user')->where($account)->value('uid'); if (!$user_id) { return app('json')->fail('查询的手机号用户不存在'); } From c0907dbeade2a964283516092c1aa24a766fb14d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 15:24:42 +0800 Subject: [PATCH 05/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/server/StoreProduct.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 8c2871d7..f210075a 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -138,8 +138,12 @@ class StoreProduct extends BaseController $data['mer_id'] = $merId; $typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id'); $productType = $merchant->type_id == $typeSupplyChainId ? 98 : 0; - $this->repository->edit($id, $data, $merId, $productType, 1); - return app('json')->success('编辑成功'); + $product=$this->repository->edit($id, $data, $merId, $productType, 1); + if ($product) { + return app('json')->success('编辑成功'); + } else { + return app('json')->fail('编辑失败'); + } } /** From 4e5abd68364b6a63d1dfbd8f9da47f41a3df591b Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Mon, 20 Nov 2023 16:15:45 +0800 Subject: [PATCH 06/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E5=AD=90=E5=BA=94=E7=94=A8=E8=A7=A3=E6=9E=90=E4=B8=AD=E5=8F=B0?= =?UTF-8?q?token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 39 ++++++++++++++++++++++++++++- route/api.php | 1 + vendor/firebase/php-jwt/src/JWT.php | 21 ++++++++-------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index cf1b61bb..049c5e0d 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -34,7 +34,6 @@ use crmeb\services\SmsService; use crmeb\services\WechatService; use crmeb\services\WechatTemplateMessageService; use Exception; -use Firebase\JWT\JWT; use Gregwar\Captcha\CaptchaBuilder; use Gregwar\Captcha\PhraseBuilder; use Overtrue\Socialite\AccessToken; @@ -57,6 +56,11 @@ use app\common\service\TopClient; use app\controller\api\Ceshi; use taobao\request\TbkItemInfoGetRequest; use app\common\repositories\store\product\ProductRepository; +use Firebase\JWT\JWT; +use Firebase\JWT\Key; +use Firebase\JWT\SignatureInvalidException; +use Firebase\JWT\BeforeValidException; +use Firebase\JWT\ExpiredException; use think\facade\App; /** @@ -67,6 +71,39 @@ use think\facade\App; */ class Auth extends BaseController { + public function parseToken(UserRepository $repository) + { + $token = $this->request->param('token'); + $app_key = 'ae47e94a7dcd1fdfacb499b60e361a8d'; + try { + JWT::$leeway = 10; //当前时间减去10秒,时间留点余地 + // jwt ^5.0 + // $decoded = JWT::decode($token, Config::get('app.app_key', 'default'), array('HS256')); + // jwt ^6.9 + // $decoded = JWT::decode($token, new Key(env('app.app_key', '123456'), 'HS256')); + $decoded = JWT::decode($token, new Key($app_key, 'HS256')); + $decodedArray = json_decode(json_encode($decoded), true); + $jwtData = $decodedArray['data'] ?? []; + if (empty($jwtData['phone'])) { + return app('json')->fail('解析数据缺少phone'); + } + $user = $repository->accountByUser($jwtData['phone']); + $user_type = 'app'; + if (!$user) $user = $repository->registr($jwtData['phone'], null, $user_type); + $user = $repository->mainUser($user); + $tokenInfo = $repository->createToken($user); + $repository->loginAfter($user); + return app('json')->success($repository->returnToken($user, $tokenInfo)); + } catch(\Firebase\JWT\SignatureInvalidException $e) { + return app('json')->fail('签名错误'); + } catch(\Firebase\JWT\BeforeValidException $e) { + return app('json')->fail('token无效'); + } catch(\Firebase\JWT\ExpiredException $e) { + return app('json')->fail('token已过期'); + } catch(\Exception $e) { + return app('json')->fail('非法请求'); + } + } public function caiji() { $url=$this->request->host(); diff --git a/route/api.php b/route/api.php index e47ccf46..bd7c118c 100644 --- a/route/api.php +++ b/route/api.php @@ -23,6 +23,7 @@ Route::group('api/', function () { Route::any('test', 'api.Auth/test'); Route::any('dotest', 'api.Auth/dotest'); Route::any('caiji', 'api.Auth/caiji'); + Route::any('parse/token', 'api.Auth/parseToken'); Route::any('app/version', 'api.Auth/appVersion'); Route::post('merchant/syncStatus/:id', 'api.Auth/merchantStatus'); Route::get('business/agree', 'api.Auth/businessAgree'); diff --git a/vendor/firebase/php-jwt/src/JWT.php b/vendor/firebase/php-jwt/src/JWT.php index ec1641bc..0ee7712b 100644 --- a/vendor/firebase/php-jwt/src/JWT.php +++ b/vendor/firebase/php-jwt/src/JWT.php @@ -138,20 +138,21 @@ class JWT // Check the nbf if it is defined. This is the time that the // token can actually be used. If it's not yet that time, abort. - if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { - throw new BeforeValidException( - 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf) - ); - } + // 取消时间验证 + // if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { + // throw new BeforeValidException( + // 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf) + // ); + // } // Check that this token has been created before 'now'. This prevents // using tokens that have been created for later use (and haven't // correctly used the nbf claim). - if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { - throw new BeforeValidException( - 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat) - ); - } + // if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { + // throw new BeforeValidException( + // 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat) + // ); + // } // Check if this token has expired. if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { From b1d1d54187fb86df2a8bf7bc95ea7665f34dea39 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 20 Nov 2023 17:20:46 +0800 Subject: [PATCH 07/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/firebase/php-jwt/src/JWT.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vendor/firebase/php-jwt/src/JWT.php b/vendor/firebase/php-jwt/src/JWT.php index 0ee7712b..151a9734 100644 --- a/vendor/firebase/php-jwt/src/JWT.php +++ b/vendor/firebase/php-jwt/src/JWT.php @@ -139,20 +139,20 @@ class JWT // Check the nbf if it is defined. This is the time that the // token can actually be used. If it's not yet that time, abort. // 取消时间验证 - // if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { - // throw new BeforeValidException( - // 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf) - // ); - // } + if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { + throw new BeforeValidException( + 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf) + ); + } // Check that this token has been created before 'now'. This prevents // using tokens that have been created for later use (and haven't // correctly used the nbf claim). - // if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { - // throw new BeforeValidException( - // 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat) - // ); - // } + if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { + throw new BeforeValidException( + 'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat) + ); + } // Check if this token has expired. if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { From 5867fe5895a3d90dac3d2efcbc22da3d1e046860 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 21 Nov 2023 09:37:09 +0800 Subject: [PATCH 08/38] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index fddaa417..4fc2c7da 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -284,8 +284,9 @@ class ProductRepository extends BaseRepository $spuData['price'] = $settleParams['data']['price']; $spuData['mer_id'] = $merId; $spuData['mer_labels'] = $data['mer_labels']; - Db::transaction(function () use ($id, $data, $productType, $settleParams, $content, $product, $spuData, $merId) { - $this->save($id, $settleParams, $content, $product, $productType); + Db::startTrans(); + try{ + $res=$this->save($id, $settleParams, $content, $product, $productType); // if ($productType == 1) { //秒杀商品 // $dat = $this->setSeckillProduct($data); // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); @@ -300,8 +301,13 @@ class ProductRepository extends BaseRepository if ($data['status'] == 0) { event('product.sell', ['product_id' => [$id]]); } - app()->make(SpuRepository::class)->changeStatus($id, $productType); - }); + app()->make(SpuRepository::class)->changeStatus($id, $productType); + Db::commit(); + return $res; + }catch(\Exception $e){ + Db::rollback(); + return false; + } } public function freeTrial(int $id, array $data, int $merId) From 9b5ed65ae93171d047cc6ca57bddf176d15b240e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 21 Nov 2023 09:44:23 +0800 Subject: [PATCH 09/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/store/product/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/model/store/product/Product.php b/app/common/model/store/product/Product.php index c1a46889..ad2ad596 100644 --- a/app/common/model/store/product/Product.php +++ b/app/common/model/store/product/Product.php @@ -377,7 +377,7 @@ class Product extends BaseModel } public function content() { - return $this->hasOne(ProductContent::class,'product_id','product_id'); + return $this->hasOne(ProductContent::class,'product_id','product_id')->where('type',1); } protected function temp() { From 33e96588a31fa9a21383fb7ae55a49c39188e3bd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 21 Nov 2023 16:20:48 +0800 Subject: [PATCH 10/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 331 ++++++++++-------- .../store/product/ProductRepository.php | 2 + .../api/store/merchant/MerchantIntention.php | 18 +- app/controller/merchant/store/StoreImport.php | 56 +-- .../merchant/store/StoreImport.php.bak | 120 ------- .../api/MerchantIntentionValidate.php | 2 +- crmeb/services/SpreadsheetExcelService.php | 1 + 7 files changed, 239 insertions(+), 291 deletions(-) delete mode 100644 app/controller/merchant/store/StoreImport.php.bak diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 15d9250f..d9bcdf6a 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -143,25 +143,25 @@ class StoreOrderRepository extends BaseRepository throw new ValidateException('未开启余额支付'); if ($user['now_money'] < $groupOrder['pay_price']) throw new ValidateException('余额不足,请更换支付方式'); - Db::startTrans(); - try{ - $user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2); - $user->save(); - $userBillRepository = app()->make(UserBillRepository::class); - $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [ - 'link_id' => $groupOrder['group_order_id'], - 'status' => 1, - 'title' => '购买商品', - 'number' => $groupOrder['pay_price'], - 'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品', - 'balance' => $user->now_money - ]); - $this->paySuccess($groupOrder); - Db::commit(); - }catch (Exception $e) { - Db::rollback(); - throw new ValidateException('余额支付失败'); - } + Db::startTrans(); + try { + $user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2); + $user->save(); + $userBillRepository = app()->make(UserBillRepository::class); + $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [ + 'link_id' => $groupOrder['group_order_id'], + 'status' => 1, + 'title' => '购买商品', + 'number' => $groupOrder['pay_price'], + 'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品', + 'balance' => $user->now_money + ]); + $this->paySuccess($groupOrder); + Db::commit(); + } catch (Exception $e) { + Db::rollback(); + throw new ValidateException('余额支付失败'); + } return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]); } @@ -261,15 +261,14 @@ class StoreOrderRepository extends BaseRepository if ($order->activity_type == 99) { $cartIdArray = explode(',', $order->cart_id); $ecartList = Db::name('store_cart')->whereIn('cart_id', $cartIdArray)->select(); - foreach($ecartList as $ecart) { + foreach ($ecartList as $ecart) { if (!empty($ecart['source_id'])) { Db::name('community')->where('community_id', $ecart['source_id'])->update(['entrust_order_id' => $order->order_id ?? 0]); } } } // 订单的类型 0 发货 1 自提 - if ($order->order_type == 1 && $order->status != 10) - { + if ($order->order_type == 1 && $order->status != 10) { $order->verify_code = $this->verifyCode(); } $order->save(); @@ -291,13 +290,12 @@ class StoreOrderRepository extends BaseRepository $flag = false; } } - if ($order->order_type == 0) - { + if ($order->order_type == 0) { //发起队列物流信息处理 //event('order.sendGoodsCode', $order); Queue::push(SendGoodsCodeJob::class, $order); } - + // 商户流水账单数据 $finance[] = [ 'order_id' => $order->order_id, @@ -332,9 +330,8 @@ class StoreOrderRepository extends BaseRepository $_order_rate = bcmul($_payPrice, $commission_rate, 2); $_payPrice = bcsub($_payPrice, $_order_rate, 2); - // 结算各镇 小组佣金 - event('order.paySuccessOrder', compact('order','_order_rate')); - + // 结算各镇 小组佣金 + event('order.paySuccessOrder', compact('order', '_order_rate')); } if (!$presell) { @@ -478,14 +475,14 @@ class StoreOrderRepository extends BaseRepository Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]); Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]); app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id); - $groupOrder=$groupOrder->toArray(); + $groupOrder = $groupOrder->toArray(); event('order.paySuccess', compact('groupOrder')); //店内扫码支付 if (isset($groupOrder['micro_pay']) && $groupOrder['micro_pay'] == 1) { $order = $this->dao->search(['uid' => $groupOrder->uid])->where('group_order_id', $groupOrder->group_order_id)->find(); $order->status = 2; $order->verify_time = date('Y-m-d H:i:s'); - $user=$order->user; + $user = $order->user; event('order.take.before', compact('order')); Db::transaction(function () use ($order, $user) { $this->takeAfter($order, $user); @@ -555,7 +552,7 @@ class StoreOrderRepository extends BaseRepository return $cart['productAssistAttr']['assist_price']; } else if ($cart['product_type'] == '4') { return $cart['activeSku']['active_price']; - // 更新调货价格 + // 更新调货价格 } else if ($cart['product_type'] == '98') { // if ($cart['source_id'] > 0) { // $resale_find = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->find(); @@ -570,12 +567,12 @@ class StoreOrderRepository extends BaseRepository // } else { // return $cart['productAttr']['price']; // } - if($cart['source']== StoreCartDao::SOURCE_PROCURE){ + if ($cart['source'] == StoreCartDao::SOURCE_PROCURE) { return $cart['productAttr']['procure_price']; - }else{ + } else { return $cart['productAttr']['price']; } - // 更新委托价格 + // 更新委托价格 } else if ($cart['product_type'] == '99') { if ($cart['source_id'] > 0) { $price = Db::name('entrust')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price'); @@ -602,7 +599,7 @@ class StoreOrderRepository extends BaseRepository return 0; } else if ($cart['product_type'] == '4') { return 0; - // 更新调货价格 + // 更新调货价格 } else if ($cart['product_type'] == '98') { $price = Db::name('resale')->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price'); if ($price) { @@ -610,7 +607,7 @@ class StoreOrderRepository extends BaseRepository } else { return $cart['productAttr']['price']; } - // 更新委托价格 + // 更新委托价格 } else if ($cart['product_type'] == '99') { $price = Db::name('entrust')->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price'); if ($price) { @@ -639,7 +636,7 @@ class StoreOrderRepository extends BaseRepository * @author xaboy * @day 2020/6/10 */ - public function userOrderNumber(int $uid, $product_type=0) + public function userOrderNumber(int $uid, $product_type = 0) { //activity_type:0普通订单 98采购订单 99委托商品 //$noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid, $product_type); @@ -841,14 +838,14 @@ class StoreOrderRepository extends BaseRepository if ($order['status'] != 1 || $order['order_type']) throw new ValidateException('订单状态有误'); $func = 'createUserLog'; - if (!$user){ + if (!$user) { $func = 'createSysLog'; $user = $order->user; } -// if (!$user) { -// -// throw new ValidateException('用户不存在'); -// } + // if (!$user) { + // + // throw new ValidateException('用户不存在'); + // } $order->status = 2; $order->verify_time = date('Y-m-d H:i:s'); event('order.take.before', compact('order')); @@ -861,7 +858,7 @@ class StoreOrderRepository extends BaseRepository 'change_message' => '已收货', 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE, ]; - Db::transaction(function () use ($order, $user,$storeOrderStatusRepository,$orderStatus,$func) { + Db::transaction(function () use ($order, $user, $storeOrderStatusRepository, $orderStatus, $func) { $this->takeAfter($order, $user); $order->save(); $storeOrderStatusRepository->{$func}($orderStatus); @@ -878,14 +875,14 @@ class StoreOrderRepository extends BaseRepository * @param int|null $orderType * @return array */ - public function OrderTitleNumber(?int $merId, ?int $orderType, ?int $product_type=0) + public function OrderTitleNumber(?int $merId, ?int $orderType, ?int $product_type = 0) { $where = []; $sysDel = $merId ? 0 : null; //商户删除 if ($merId) $where['mer_id'] = $merId; //商户订单 if ($orderType === 0) $where['order_type'] = 0; //普通订单 if ($orderType === 1) $where['take_order'] = 1; //已核销订单 - if ($product_type!=0) $where['product_type'] = $product_type; //商品属性 + if ($product_type != 0) $where['product_type'] = $product_type; //商品属性 //1: 未支付 2: 未发货 3: 待收货 4: 待评价 5: 交易完成 6: 已退款 7: 已删除 8: 已支付 $all = $this->dao->search($where, $sysDel)->where($this->getOrderType(0))->count(); $statusAll = $all; @@ -961,7 +958,7 @@ class StoreOrderRepository extends BaseRepository $param['StoreOrder.paid'] = 1; break; // 已支付 case 20: - $param['StoreOrder.status'] =[2,3]; + $param['StoreOrder.status'] = [2, 3]; break; // 已收货的商品才可以继续导入 default: unset($param['StoreOrder.is_del']); @@ -1089,7 +1086,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CHANGE, ]; - Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group,$storeOrderStatusRepository,$orderStatus,$service_id) { + Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group, $storeOrderStatusRepository, $orderStatus, $service_id) { $orderGroup->total_price = $_group['total_price']; $orderGroup->pay_price = $_group['pay_price']; $orderGroup->pay_postage = $_group['pay_postage']; @@ -1100,7 +1097,7 @@ class StoreOrderRepository extends BaseRepository $this->changOrderProduct($id, $data); if ($service_id) { - $storeOrderStatusRepository->createServiceLog($service_id,$orderStatus); + $storeOrderStatusRepository->createServiceLog($service_id, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } @@ -1239,7 +1236,7 @@ class StoreOrderRepository extends BaseRepository 'mer_id' => $merId ]; - if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0 ) { + if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0) { $imp['status'] = 0; $imp['mark'] = '订单信息不存在或状态错误'; } else { @@ -1257,7 +1254,7 @@ class StoreOrderRepository extends BaseRepository $imp['delivery_id'] = $ret['delivery_id']; $imp['delivery_name'] = $ret['delivery_name']; } else { - $this->delivery($item, $merId,[ + $this->delivery($item, $merId, [ 'delivery_id' => $params['delivery_id'], 'delivery_type' => $params['delivery_type'], 'delivery_name' => $params['delivery_name'], @@ -1315,7 +1312,7 @@ class StoreOrderRepository extends BaseRepository 'to_name' => $data['to_name'], ]; Db::transaction(function () use ($merId, $id, $delivery, $make, $dump, $service_id) { - $this->delivery($id, $merId, $delivery,$service_id); + $this->delivery($id, $merId, $delivery, $service_id); $arr = [ 'type' => 'mer_dump', 'num' => -1, @@ -1327,22 +1324,22 @@ class StoreOrderRepository extends BaseRepository return $delivery; } - public function runDelivery($id, $merId, $data, $split, $method,$service_id = 0) + public function runDelivery($id, $merId, $data, $split, $method, $service_id = 0) { - return Db::transaction(function () use ($id, $merId, $data, $split, $method,$service_id) { + return Db::transaction(function () use ($id, $merId, $data, $split, $method, $service_id) { if ($split['is_split'] && !empty($split['split'])) { foreach ($split['split'] as $v) { $splitData[$v['id']] = $v['num']; } $order = $this->dao->get($id); - $newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData,$service_id); - if ($newOrder){ + $newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData, $service_id); + if ($newOrder) { $id = $newOrder->order_id; } else { throw new ValidateException('商品不能全部拆单'); } } - return $this->{$method}($id, $merId, $data,$service_id); + return $this->{$method}($id, $merId, $data, $service_id); }); } @@ -1403,17 +1400,17 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $change_type, ]; if ($service_id) { - $statusRepository->createServiceLog($service_id,$orderStatus); + $statusRepository->createServiceLog($service_id, $orderStatus); } else { $statusRepository->createAdminLog($orderStatus); } //虚拟发货后用户直接确认收获 - if($data['status'] == 2){ + if ($data['status'] == 2) { $user = app()->make(UserRepository::class)->get($order['uid']); //订单记录 - $this->takeAfter($order,$user); + $this->takeAfter($order, $user); $orderStatus = [ 'order_id' => $order->order_id, 'order_sn' => $order->order_sn, @@ -1422,7 +1419,6 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $statusRepository::ORDER_STATUS_TAKE, ]; $statusRepository->createSysLog($orderStatus); - } if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]); @@ -1447,7 +1443,7 @@ class StoreOrderRepository extends BaseRepository $make->create($id, $merId, $data, $order); //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); - $this->dao->update($id, ['delivery_type' => 5, 'status' => 1,'remark' => $data['remark']]); + $this->dao->update($id, ['delivery_type' => 5, 'status' => 1, 'remark' => $data['remark']]); $orderStatus = [ 'order_id' => $id, @@ -1457,7 +1453,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_DELIVERY_SELF, ]; if ($service_id) { - $storeOrderStatusRepository->createServiceLog($service_id,$orderStatus); + $storeOrderStatusRepository->createServiceLog($service_id, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } @@ -1473,21 +1469,24 @@ class StoreOrderRepository extends BaseRepository $whre['mer_id'] = $merId; $whre['is_system_del'] = 0; } - $res = $this->dao->getWhere($where, '*', [ - 'orderProduct', - 'user' => function ($query) { - $query->field('uid,real_name,nickname,is_svip,svip_endtime,phone'); - }, - 'refundOrder' => function ($query) { - $query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3); - }, - 'finalOrder', - 'TopSpread' => function ($query) { - $query->field('uid,nickname,avatar'); - }, - 'spread' => function ($query) { - $query->field('uid,nickname,avatar'); - }, + $res = $this->dao->getWhere( + $where, + '*', + [ + 'orderProduct', + 'user' => function ($query) { + $query->field('uid,real_name,nickname,is_svip,svip_endtime,phone'); + }, + 'refundOrder' => function ($query) { + $query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3); + }, + 'finalOrder', + 'TopSpread' => function ($query) { + $query->field('uid,nickname,avatar'); + }, + 'spread' => function ($query) { + $query->field('uid,nickname,avatar'); + }, ] ); if (!$res) throw new ValidateException('数据不存在'); @@ -1609,17 +1608,17 @@ class StoreOrderRepository extends BaseRepository ]); $count = $query->count(); $list = $query->page($page, $limit)->select()->append(['refund_extension_one', 'refund_extension_two']) - ->each(function($item){ + ->each(function ($item) { // 1:退款中 2:部分退款 3 = 全退 $refunding = 0; if ($item['orderProduct']) { - $is_refund = array_column($item['orderProduct']->toArray(),'is_refund'); + $is_refund = array_column($item['orderProduct']->toArray(), 'is_refund'); $is_refund = array_unique($is_refund); - if (in_array(1,$is_refund)) { + if (in_array(1, $is_refund)) { $refunding = 1; - } else if (in_array(2,$is_refund)) { + } else if (in_array(2, $is_refund)) { $refunding = 2; - } else if (in_array(3,$is_refund)) { + } else if (in_array(3, $is_refund)) { $refunding = 3; } } @@ -1773,7 +1772,7 @@ class StoreOrderRepository extends BaseRepository if ($status == 1) { $query = $this->dao->search($where)->where($this->getOrderType($status))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where('StoreOrder.is_del', 0); } else { - $arr=$this->getOrderType($status); + $arr = $this->getOrderType($status); $query = $this->dao->search($where)->where($arr)->where('StoreOrder.is_del', 0); } @@ -1813,10 +1812,11 @@ class StoreOrderRepository extends BaseRepository unset($order['takeOrderList'], $order->interest); } - return compact( 'count','list'); + return compact('count', 'list'); } - public function getOrderStatusV2($order) { + public function getOrderStatusV2($order) + { //订单状态 1 未支付 2待发货 3待收货 4待评价 5交易完成 6已退款 7待核销 8先货后款待结算 9待商家确认 $order->order_status = 0; if ($order->paid == 0) { @@ -1998,7 +1998,7 @@ class StoreOrderRepository extends BaseRepository public function verifyOrder(int $id, int $merId, array $data, $serviceId = 0) { - $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId,'verify_code' => $data['verify_code'],'order_type' => 1],'*',['orderProduct']); + $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']); if (!$order) throw new ValidateException('订单不存在'); if (!$order->paid) throw new ValidateException('订单未支付'); if ($order['status']) throw new ValidateException('订单已全部核销,请勿重复操作'); @@ -2013,7 +2013,7 @@ class StoreOrderRepository extends BaseRepository event('order.verify.before', compact('order')); //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); - Db::transaction(function () use ($order,$storeOrderStatusRepository,$serviceId) { + Db::transaction(function () use ($order, $storeOrderStatusRepository, $serviceId) { $this->takeAfter($order, $order->user); $order->save(); $orderStatus = [ @@ -2023,12 +2023,11 @@ class StoreOrderRepository extends BaseRepository 'change_message' => '订单已核销', 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE, ]; - if ($serviceId){ - $storeOrderStatusRepository->createServiceLog($serviceId,$orderStatus); + if ($serviceId) { + $storeOrderStatusRepository->createServiceLog($serviceId, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } - }); event('order.verify', compact('order')); } @@ -2245,7 +2244,6 @@ class StoreOrderRepository extends BaseRepository if (count($couponId)) { app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]); } - } //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); @@ -2292,7 +2290,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_DELETE, ]; $productRepository = app()->make(ProductRepository::class); - Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository,$productRepository) { + Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository, $productRepository) { $order->is_del = 1; $order->save(); $storeOrderStatusRepository->createUserLog($orderStatus); @@ -2476,18 +2474,18 @@ class StoreOrderRepository extends BaseRepository * @author Qinii * @day 2023/2/22 */ - public function childrenList($id,$merId) + public function childrenList($id, $merId) { $data = $this->dao->get($id); - $query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id','<>',$id); - if ($merId) $query->where('mer_id',$merId); + $query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id', '<>', $id); + if ($merId) $query->where('mer_id', $merId); if ($data['main_id']) { - $query->where(function($query) use($data,$id){ - $query->where('main_id',$data['main_id'])->whereOr('order_id',$data['main_id']); + $query->where(function ($query) use ($data, $id) { + $query->where('main_id', $data['main_id'])->whereOr('order_id', $data['main_id']); }); } else { - $query->where('main_id',$id); - } + $query->where('main_id', $id); + } return $query->select(); } @@ -2505,46 +2503,94 @@ class StoreOrderRepository extends BaseRepository $data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1); if (!$data) return false; unset($data[0]); - $mer_cate_id=Db::name('store_category')->where('mer_id',$merId)->where('cate_name','默认分类')->value('store_category_id'); - if (!$mer_cate_id ||$mer_cate_id==0){ - $mer_cate=['pid'=>0,'cate_name'=>'默认分类','path'=>'/','mer_id'=>$merId,'sort'=>0,'is_show'=>1,'create_time'=>date('Y-m-d H:i:s')]; - $mer_cate_id=Db::name('store_category')->insertGetId($mer_cate); - $mer_cate['pid']=$mer_cate_id; - $mer_cate['path']='/'.$mer_cate_id.'/'; - $mer_cate['level']=1; - $mer_cate_id=Db::name('store_category')->insertGetId($mer_cate); + $mer_cate_id = Db::name('store_category')->where('mer_id', $merId)->where('cate_name', '默认分类')->value('store_category_id'); + if (!$mer_cate_id || $mer_cate_id == 0) { + $mer_cate = ['pid' => 0, 'cate_name' => '默认分类', 'path' => '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')]; + $mer_cate_id = Db::name('store_category')->insertGetId($mer_cate); + $mer_cate['pid'] = $mer_cate_id; + $mer_cate['path'] = '/' . $mer_cate_id . '/'; + $mer_cate['level'] = 1; + $mer_cate_id = Db::name('store_category')->insertGetId($mer_cate); } - // $type=Db::name('merchant')->where('mer_id',$merId)->value('type_id'); - $typeCode=Db::name('merchant_type')->where('mer_type_id',$merId)->value('type_code'); - $product_type=0; - // if ($type==12){ - if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ - $product_type=98;//供应链 + $typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code'); + $product_type = 0; + if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) { + $product_type = 98; //供应链 } foreach ($data as $datum) { -// $find=Db::name('store_product')->where('mer_id', $merId)->where('bar_code', $datum['where']['bar_code'])->find(); -// if ($find){ -// Db::name('store_product')->where('product_id', $find['product_id'])->update($datum['value']); -// }else{ - $store_category_id=Db::name('store_category')->where('mer_id',0)->where('cate_name',$datum['value']['cate_id'])->value('store_category_id'); - if ($store_category_id==null){ - $store_category_id=438; + $find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find(); + $attr_one = explode('|', $datum['value']['attr_one']); + $attr_two = explode('|', $datum['value']['attr_two']); + $arr = []; + if ($find) { + $store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find(); + if ($store_product_attr_value) { + Log::error('xls导入商品:已经导入过该规格了'); + return false; + } + foreach ($attr_one as $kk => $vv) { + /**查询当前规格是否存在 */ + $attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk) + ->find(); + if ($attr_values_find) { + $attr_values= $attr_values_find['attr_values']; + $attr_values = explode('-!-', $attr_values); + if (!in_array($vv, $attr_values)) { + $attr_values[] = $vv; + $attr_values = implode('-!-', $attr_values); + Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); + } + } else { + $attr_values = $vv; + + Db::name('store_product_attr')->insert( + [ + 'product_id' => $exist['product_id'], + 'attr_name' => $kk, 'attr_values' => $attr_values + ] + ); + } + } + $attrValue['stock'] = 1; + $unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type); + $attrValue['unique'] = $unique; + $attrValue['detail'] = json_encode($attrValue['detail']); + $attrValue['product_id'] = $find['product_id']; + $attrValue['mer_id'] = $merId; + Db::name('store_product_attr_value')->insert($attrValue); + } else { + $cate_id = 0; + $spec_type = 0; + $cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id'); + if ($cate_id_one) { + $cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id'); + if ($cate_id_two) { + $cate_id = $cate_id_two; + } + } + foreach ($attr_one as $k => $v) { + $arr[] = [ + 'value' => $v, + 'detail' => [$attr_two[$k] ?? []], + 'inputVisible' => false + ]; + $spec_type = 1; } $datas = [ "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", "slider_image" => [ 0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", ], - "store_name" => $datum['value']['store_name'].' '.$datum['value']['specifications'], + "store_name" => $datum['value']['store_name'], "store_info" => $datum['value']['store_name'], - "keyword" => $datum['value']['keyword'], - "bar_code" => $datum['value']['bar_code'], + "keyword" => '', + "bar_code" => (int) $datum['value']['bar_code'], "guarantee_template_id" => "", - "cate_id" => $store_category_id,//要修改 + "cate_id" => $cate_id, "mer_cate_id" => [ - 0 => $mer_cate_id//要修改 + 0 => $mer_cate_id //要修改 ], - 'product_type'=>$product_type, + 'product_type' => $product_type, "unit_name" => $datum['value']['unit_name'], "sort" => 0, "is_show" => "", @@ -2554,14 +2600,15 @@ class StoreOrderRepository extends BaseRepository "video_link" => "", "temp_id" => "", "content" => "", - "spec_type" => 0, + "spec_type" => $spec_type, "extension_type" => 0, - "attr" => [], + "attr" => $arr, "mer_labels" => [], "delivery_way" => [ - 0 => "2" + 0 => "2", + 1 => "1" ], - "delivery_free" => 1, + "delivery_free" => 0, "param_temp_id" => [], "extend" => [], "brand_id" => "", @@ -2572,11 +2619,12 @@ class StoreOrderRepository extends BaseRepository [ "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", "price" => $datum['value']['price'], - "cost" => $datum['value']['price'], + "cost" => $datum['value']['cost'], "ot_price" => $datum['value']['price'], "svip_price" => null, - "stock" => $datum['value']['stock'], - "bar_code" => $datum['value']['bar_code'], + "procure_price" => $datum['value']['procure_price'], + "stock" => 1, + "bar_code" => (int)$datum['value']['bar_code'], "weight" => 0, "volume" => 0, ], @@ -2591,11 +2639,15 @@ class StoreOrderRepository extends BaseRepository "mer_status" => 1, "rate" => 3, ]; - $data_list=[ - 'data'=>$datas, - 'product_type'=>$product_type, + $data_list = [ + 'data' => $datas, + 'product_type' => $product_type, ]; - Queue::push(ProductImportJob::class,$data_list); + $make = app()->make(ProductRepository::class); + $id = $make->create($datas, 98); + halt($id); + Queue::push(ProductImportJob::class, $data_list); + } } return true; } @@ -2781,7 +2833,7 @@ class StoreOrderRepository extends BaseRepository * @param $orderSn * 更新扫描发货状态 */ - public function deliveryGoods($orderId, $orderSn, $logisticsCode='') + public function deliveryGoods($orderId, $orderSn, $logisticsCode = '') { if ($logisticsCode) { $order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('logistics_code', $logisticsCode)->where('StoreOrder.status', 1)->where('StoreOrder.is_del', 0)->find(); @@ -2792,7 +2844,7 @@ class StoreOrderRepository extends BaseRepository throw new ValidateException('订单不存在或编码code错误'); if ($order['order_type']) throw new ValidateException('订单类型错误'); - + if ($logisticsCode) { $order->status = 2; $order->mark = '快递员已完成送货'; @@ -2803,5 +2855,4 @@ class StoreOrderRepository extends BaseRepository } $order->save(); } - } diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 4fc2c7da..8226e59f 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -224,6 +224,8 @@ class ProductRepository extends BaseRepository public function create(array $data, int $productType = 0, $conType = 0) { if (!$data['spec_type']) { + halt($data['spec_type']); + $data['attr'] = []; if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); } diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 86f321a8..14d8897e 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -341,8 +341,8 @@ class MerchantIntention extends BaseController 'name', 'code', 'images', - 'merchant_category_name', 'mer_type_id', + 'merchant_category_id', 'social_credit_code', 'area_id', 'street_id', @@ -360,14 +360,14 @@ class MerchantIntention extends BaseController if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) { throw new ValidateException('店铺类型不存在'); } - if ($data['merchant_category_name'] == '') { - throw new ValidateException('商户分类,不能为空'); - } - $merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id'); - if(!$merchant_category_id){ - throw new ValidateException('没有对应的商户分类,请联系工作人员添加'); - } - $data['merchant_category_id']=$merchant_category_id; + // if ($data['merchant_category_name'] == '') { + // throw new ValidateException('商户分类,不能为空'); + // } + // $merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id'); + // if(!$merchant_category_id){ + // throw new ValidateException('没有对应的商户分类,请联系工作人员添加'); + // } + // $data['merchant_category_id']=$merchant_category_id; unset($data['code']); return $data; } diff --git a/app/controller/merchant/store/StoreImport.php b/app/controller/merchant/store/StoreImport.php index 19214971..60d56ee6 100644 --- a/app/controller/merchant/store/StoreImport.php +++ b/app/controller/merchant/store/StoreImport.php @@ -89,29 +89,10 @@ class StoreImport extends BaseController $res = $upload->getUploadInfo(); $path = rtrim(public_path(),'/').$res['dir']; $data = []; + $type_id=Db::name('merchant')->where('mer_id',$this->request->merId())->value('type_id'); switch ($type){ case 'product': - $check =[ - 'A1'=>'商品名称', - 'B1'=>'商品简介', - 'C1'=>'关键字', - 'D1'=>'商品条码', - 'E1'=>'分类', - 'F1'=>'单位名', - 'G1'=>'出售价', - 'H1'=>'总库存', - 'I1'=>'规格', - ]; - SpreadsheetExcelService::instance()->checkImport($path,$check); - $data = [ - 'mer_id' => $this->request->merId(), - 'data' => [ - 'path' => $path, - 'sql' => ['store_name' => 'A', 'store_info' => 'B', 'keyword' => 'C', 'bar_code' => 'D', 'cate_id' => 'E', 'unit_name' => 'F', 'price' => 'G', 'stock' => 'H', 'specifications' => 'I'], - 'where' => ['bar_code' => 'D'], - ] - ]; - app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']); + $this->getXlsList($type_id,$path); return app('json')->success('开始导入数据,请稍后在列表中查看!'); break; case 'delivery' : @@ -177,5 +158,38 @@ class StoreImport extends BaseController } return app('json')->fail('数据类型错误'); } + + public function getXlsList($type_id,$path){ + if($type_id==12){ + $check =[ + 'A1'=>'商品名称(必填)', + 'B1'=>'平台一级类目(必填)', + 'C1'=>'平台二级类目(必填)', + 'D1'=>'店铺一级商品分类', + 'E1'=>'店铺二级商品分类', + 'F1'=>'规格组', + 'G1'=>'规格值', + 'H1'=>'销售单位', + 'I1'=>'批发价(必填)', + 'J1'=>'零售价(必填)', + 'K1'=>'成本价', + 'L1'=>'商品条码', + 'M1'=>'商品品牌', + ]; + SpreadsheetExcelService::instance()->checkImport($path,$check); + $data = [ + 'mer_id' => $this->request->merId(), + 'data' => [ + 'path' => $path, + 'sql' => ['store_name' => 'A', 'cate_id_one' => 'B', 'cate_id_two' => 'C', 'cate_id_one_mer' => 'D', 'cate_id_one_two' => 'E', + 'attr_one' => 'F', 'attr_two' => 'G', 'unit_name' => 'H', 'procure_price' => 'I','price'=>'J','cost'=>'K','bar_code'=>'L','brand_id'=>'M'], + 'where' => ['bar_code' => 'L'], + ] + ]; + app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']); + }else{ + + } + } } diff --git a/app/controller/merchant/store/StoreImport.php.bak b/app/controller/merchant/store/StoreImport.php.bak deleted file mode 100644 index 225ee328..00000000 --- a/app/controller/merchant/store/StoreImport.php.bak +++ /dev/null @@ -1,120 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace app\controller\merchant\store; - -use app\common\repositories\store\ExcelRepository; -use app\common\repositories\store\order\StoreImportDeliveryRepository; -use app\common\repositories\store\order\StoreOrderRepository; -use crmeb\jobs\ImportSpreadsheetExcelJob; -use crmeb\services\ExcelService; -use crmeb\services\SpreadsheetExcelService; -use crmeb\services\UploadService; -use think\App; -use crmeb\basic\BaseController; -use app\common\repositories\store\order\StoreImportRepository; - -use think\facade\Queue; - -class StoreImport extends BaseController -{ - protected $repository; - - /** - * Product constructor. - * @param App $app - * @param StoreImportRepository $repository - */ - public function __construct(App $app, StoreImportRepository $repository) - { - parent::__construct($app); - $this->repository = $repository; - } - - public function lst() - { - [$page, $limit] = $this->getPage(); - $where = $this->request->params(['status','date',['import_type','delivery'],'type']); - $where['mer_id'] = $this->request->merId(); - $data = $this->repository->getList($where,$page,$limit); - return app('json')->success($data); - } - - public function detail($id) - { - $where = [ - 'import_id' => $id, - 'mer_id' => $this->request->merId() - ]; - [$page, $limit] = $this->getPage(); - $data = app()->make(StoreImportDeliveryRepository::class)->getList($where,$page, $limit); - return app('json')->success($data); - } - - public function export($id) - { - $where = [ - 'import_id' => $id, - 'mer_id' => $this->request->merId() - ]; - [$page, $limit] = $this->getPage(); - $data = app()->make(ExcelService::class)->importDelivery($where, $page, $limit); - return app('json')->success($data); - } - - /** - * TODO 导入excel信息 - * @return \think\response\Json - * @author Qinii - * @day 3/16/21 - */ - public function Import($type) - { - $file = $this->request->file('file'); - if (!$file) return app('json')->fail('请上传EXCEL文件'); - $file = is_array($file) ? $file[0] : $file; - validate(["file|文件" => ['fileExt' => 'xlsx,xls',]])->check(['file' => $file]); - - $upload = UploadService::create(1); - $ret = $upload->to('excel')->move('file'); - if ($ret === false) return app('json')->fail($upload->getError()); - $res = $upload->getUploadInfo(); - $path = rtrim(public_path(),'/').$res['dir']; - $data = []; - switch ($type){ - case 'delivery' : - SpreadsheetExcelService::instance()->checkImport($path,['E3' => '物流单号']); - $data = [ - 'mer_id' => $this->request->merId(), - 'data' => [ - 'path' => $path, - 'sql' => ['delivery_name' => 'D', 'delivery_id' => 'E',], - 'where' => ['order_sn' => 'B',], - ] - ]; - break; - default: - $data = SpreadsheetExcelService::instance()->_import($path,[],[],0); - break; - } - if(!empty($data)){ - $res = $this->repository->create($this->request->merId(),'delivery'); - $data['data']['import_id'] = $res->import_id; - -// app()->make(StoreOrderRepository::class)->setWhereDeliveryStatus($data['data'],$data['mer_id']); - - Queue::push(ImportSpreadsheetExcelJob::class,$data); - return app('json')->success('开始导入数据,请稍后在批量发货记录中查看!'); - } - return app('json')->fail('数据类型错误'); - } -} - diff --git a/app/validate/api/MerchantIntentionValidate.php b/app/validate/api/MerchantIntentionValidate.php index 4458f80e..e3d1e81d 100644 --- a/app/validate/api/MerchantIntentionValidate.php +++ b/app/validate/api/MerchantIntentionValidate.php @@ -23,7 +23,7 @@ class MerchantIntentionValidate extends Validate 'phone|手机号' => 'require|mobile', 'name|姓名' => 'require', 'mer_name|姓名' => 'require|max:32', - 'merchant_category_name|商户分类' => 'require', + 'merchant_category_id|商户分类' => 'require', 'mer_type_id|店铺类型' => 'integer', 'code|验证码' => 'require', 'images|资质' => 'array', diff --git a/crmeb/services/SpreadsheetExcelService.php b/crmeb/services/SpreadsheetExcelService.php index a838f175..48b37749 100644 --- a/crmeb/services/SpreadsheetExcelService.php +++ b/crmeb/services/SpreadsheetExcelService.php @@ -325,6 +325,7 @@ class SpreadsheetExcelService $ret = []; if (in_array($ext, ['Xlsx', 'Xls'])) { $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext); + $reader->setReadDataOnly(true); $spreadsheet = $reader->load($filePath); $sheet = $spreadsheet->getActiveSheet(); $row_count = $sheet->getHighestDataRow();//取得总行数 From e1f105d98a8807cd33eb33a3b4c8dd2474f998b1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 22 Nov 2023 15:45:46 +0800 Subject: [PATCH 11/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 82 +++++++++++-------- .../api/store/merchant/MerchantIntention.php | 8 +- app/controller/merchant/store/StoreImport.php | 26 +++++- 3 files changed, 81 insertions(+), 35 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index d9bcdf6a..418669bd 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2521,14 +2521,26 @@ class StoreOrderRepository extends BaseRepository $find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find(); $attr_one = explode('|', $datum['value']['attr_one']); $attr_two = explode('|', $datum['value']['attr_two']); + $attr=[]; $arr = []; + foreach ($attr_one as $key => $value){ + $attr[$value]=$attr_two[$key]; + $arr[] = [ + 'value' => $value, + 'detail' => [$attr_two[$key] ?? []], + 'inputVisible' => false + ]; + } + $array_values=array_values($attr); if ($find) { $store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find(); if ($store_product_attr_value) { Log::error('xls导入商品:已经导入过该规格了'); - return false; + continue; } - foreach ($attr_one as $kk => $vv) { + $is_update=false; + foreach ($attr as $kk => $vv) { + /**查询当前规格是否存在 */ $attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk) ->find(); @@ -2536,31 +2548,29 @@ class StoreOrderRepository extends BaseRepository $attr_values= $attr_values_find['attr_values']; $attr_values = explode('-!-', $attr_values); if (!in_array($vv, $attr_values)) { - $attr_values[] = $vv; - $attr_values = implode('-!-', $attr_values); - Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); - } + $attr_values[] = $vv; + $attr_values = implode('-!-', $attr_values); + Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); + $this->create_product_attr_value($find,$datum,$product_type,$attr,$merId,implode(',',$array_values)); + } + $is_update=true; } else { - $attr_values = $vv; - - Db::name('store_product_attr')->insert( - [ - 'product_id' => $exist['product_id'], - 'attr_name' => $kk, 'attr_values' => $attr_values - ] - ); + $datas=[ + 'product_id' => $find['product_id'], + 'attr_name' => $kk, 'attr_values' => $vv, + ]; + Db::name('store_product_attr')->insert($datas); } } - $attrValue['stock'] = 1; - $unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type); - $attrValue['unique'] = $unique; - $attrValue['detail'] = json_encode($attrValue['detail']); - $attrValue['product_id'] = $find['product_id']; - $attrValue['mer_id'] = $merId; - Db::name('store_product_attr_value')->insert($attrValue); + if($is_update==false){ + $this->create_product_attr_value($find,$datum,$product_type,$attr,$merId,implode(',',$array_values)); + } + } else { $cate_id = 0; - $spec_type = 0; + $spec_type = 1; + $detail = $attr; + $cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id'); if ($cate_id_one) { $cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id'); @@ -2568,14 +2578,7 @@ class StoreOrderRepository extends BaseRepository $cate_id = $cate_id_two; } } - foreach ($attr_one as $k => $v) { - $arr[] = [ - 'value' => $v, - 'detail' => [$attr_two[$k] ?? []], - 'inputVisible' => false - ]; - $spec_type = 1; - } + $datas = [ "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", "slider_image" => [ @@ -2627,6 +2630,7 @@ class StoreOrderRepository extends BaseRepository "bar_code" => (int)$datum['value']['bar_code'], "weight" => 0, "volume" => 0, + "detail" => $detail, ], ], "give_coupon_ids" => [], @@ -2645,13 +2649,27 @@ class StoreOrderRepository extends BaseRepository ]; $make = app()->make(ProductRepository::class); $id = $make->create($datas, 98); - halt($id); - Queue::push(ProductImportJob::class, $data_list); + // Queue::push(ProductImportJob::class, $data_list); } } return true; } + public function create_product_attr_value($find,$datum,$product_type,$attr_values,$merId,$sku){ + $attrValue['stock'] = 1; + $unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type); + $attrValue['unique'] = $unique; + $attrValue['detail'] = json_encode($attr_values); + $attrValue['product_id'] = $find['product_id']; + $attrValue['mer_id'] = $merId; + $attrValue['sku'] = $sku; + $attrValue['cost'] = $datum['value']['cost']; + $attrValue['ot_price'] =$datum['value']['price']; + $attrValue['price'] = $datum['value']['price']; + $attrValue['procure_price'] = $datum['value']['procure_price']; + $attrValue["image"] = "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png"; + Db::name('store_product_attr_value')->insert($attrValue); + } /** * 订单结算 * @param $id diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 14d8897e..9f563322 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -275,7 +275,7 @@ class MerchantIntention extends BaseController if ($adminRepository->fieldExists('account', $data['phone'])) throw new ValidateException('手机号已是管理员,不可申请'); $data['create_time'] = date('Y-m-d H:i:s', time()); - $this->repository->updateIntention((int)$id, $data); + $updateIntention=$this->repository->updateIntention((int)$id, $data); SwooleTaskService::admin('notice', [ 'type' => 'new_intention', 'data' => [ @@ -308,7 +308,11 @@ class MerchantIntention extends BaseController if (!$res['ok']) { throw new ValidateException('供销平台申请商户入驻失败,' . $res['msg']); } - return app('json')->success('修改成功'); + if($updateIntention){ + return app('json')->success('修改成功'); + }else{ + return app('json')->success('修改失败'); + } } public function lst() diff --git a/app/controller/merchant/store/StoreImport.php b/app/controller/merchant/store/StoreImport.php index 60d56ee6..fcc59d35 100644 --- a/app/controller/merchant/store/StoreImport.php +++ b/app/controller/merchant/store/StoreImport.php @@ -188,7 +188,31 @@ class StoreImport extends BaseController ]; app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']); }else{ - + $check =[ + 'A1'=>'商品名称(必填)', + 'B1'=>'平台一级类目(必填)', + 'C1'=>'平台二级类目(必填)', + 'D1'=>'店铺一级商品分类', + 'E1'=>'店铺二级商品分类', + 'F1'=>'规格组', + 'G1'=>'规格值', + 'H1'=>'销售单位', + 'I1'=>'零售价(必填)', + 'J1'=>'成本价', + 'K1'=>'商品条码', + 'L1'=>'商品品牌', + ]; + SpreadsheetExcelService::instance()->checkImport($path,$check); + $data = [ + 'mer_id' => $this->request->merId(), + 'data' => [ + 'path' => $path, + 'sql' => ['store_name' => 'A', 'cate_id_one' => 'B', 'cate_id_two' => 'C', 'cate_id_one_mer' => 'D', 'cate_id_one_two' => 'E', + 'attr_one' => 'F', 'attr_two' => 'G', 'unit_name' => 'H', 'price' => 'I','cost'=>'J','bar_code'=>'K','brand_id'=>'L'], + 'where' => ['bar_code' => 'K'], + ] + ]; + app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']); } } } From aca40a4b0ee678d2dfc27e3988abc56eea03a02f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 23 Nov 2023 09:56:06 +0800 Subject: [PATCH 12/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Common.php | 4 ++-- app/controller/api/store/product/StoreMicro.php | 1 + config/upload.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 9ff9ec33..74237ba3 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -161,8 +161,8 @@ class Common extends BaseController $file = is_array($file) ? $file[0] : $file; validate(["$field|图片" => [ 'fileSize' => config('upload.filesize'), - 'fileExt' => 'jpg,jpeg,png,bmp,gif', - 'fileMime' => 'image/jpeg,image/png,image/gif,application/octet-stream' + 'fileExt' => config('upload.fileExt'), + // 'fileMime' => 'image/jpeg,image/png,image/gif,application/octet-stream,application/vnd.android.package-archive' ]])->check([$field => $file]); $upload = UploadService::create(); $info = $upload->to('def')->move($field); diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index bba75b8c..9317e787 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -69,6 +69,7 @@ class StoreMicro extends BaseController //提交导入商品id public function ProductImport(){ + return app('json')->fail('该接口已废弃'); $id = $this->request->param('id', 0); $price = $this->request->param('price', 0); $stock = $this->request->param('stock', 0); diff --git a/config/upload.php b/config/upload.php index 19b46541..e1f5a6ce 100644 --- a/config/upload.php +++ b/config/upload.php @@ -19,7 +19,7 @@ return [ //上传文件大小 'filesize' => 52428800, //上传文件后缀类型 - 'fileExt' => ['jpg', 'jpeg', 'png', 'gif', 'pem', 'mp3', 'wma', 'wav', 'amr', 'mp4', 'key', 'xlsx', 'xls', 'ico', 'apk', 'ipa'], + 'fileExt' => ['jpg', 'jpeg', 'png', 'gif', 'pem', 'mp3', 'wma', 'wav', 'amr', 'mp4', 'key', 'xlsx', 'xls', 'ico', 'apk', 'ipa','wgt'], //上传文件类型 'fileMime' => ['image/jpeg', 'image/gif', 'image/png', 'text/plain', 'audio/mpeg', 'image/vnd.microsoft.icon'], //驱动模式 From ecf559d4bc75d77c6c579cce73bd7f23cf4317cd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 23 Nov 2023 10:10:23 +0800 Subject: [PATCH 13/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0swoole=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/swoole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/swoole.php b/config/swoole.php index 8429e475..1f830cfd 100644 --- a/config/swoole.php +++ b/config/swoole.php @@ -32,7 +32,7 @@ return [ 'task_max_request' => 2000, 'enable_static_handler' => true, 'document_root' => root_path('public'), - 'package_max_length' => 50 * 1024 * 1024, + 'package_max_length' => 100 * 1024 * 1024, 'buffer_output_size' => 10 * 1024 * 1024, 'socket_buffer_size' => 128 * 1024 * 1024, 'max_request' => 3000, From 797090de46c551fe366cd9a1c5ccbe1523030927 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 23 Nov 2023 10:48:04 +0800 Subject: [PATCH 14/38] =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8F=96=E8=B4=A7?= =?UTF-8?q?=E7=A0=81=E5=92=8C=E4=BF=AE=E6=94=B9=E6=A0=B8=E9=94=80=E7=A0=81?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 5 +++- app/controller/merchant/store/order/Order.php | 30 ++++++++++++------- route/merchant/order.php | 3 ++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 418669bd..9beed35c 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -1998,8 +1998,11 @@ class StoreOrderRepository extends BaseRepository public function verifyOrder(int $id, int $merId, array $data, $serviceId = 0) { - $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']); + $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId, 'order_type' => 1], '*', ['orderProduct']); if (!$order) throw new ValidateException('订单不存在'); + if($order['verify_code']!=$data['verify_code']){ + throw new ValidateException('核销码不正确'); + } if (!$order->paid) throw new ValidateException('订单未支付'); if ($order['status']) throw new ValidateException('订单已全部核销,请勿重复操作'); foreach ($data['data'] as $v) { diff --git a/app/controller/merchant/store/order/Order.php b/app/controller/merchant/store/order/Order.php index a31d4421..98ea1511 100644 --- a/app/controller/merchant/store/order/Order.php +++ b/app/controller/merchant/store/order/Order.php @@ -144,11 +144,10 @@ class Order extends BaseController public function delivery($id) { $type = $this->request->param('delivery_type'); - $split = $this->request->params(['is_split',['split',[]]]); + $split = $this->request->params(['is_split', ['split', []]]); if (!$this->repository->merDeliveryExists($id, $this->request->merId())) return app('json')->fail('订单信息或状态错误'); - switch ($type) - { + switch ($type) { case 3: //虚拟发货 $data = $this->request->params([ 'delivery_type', @@ -170,7 +169,8 @@ class Order extends BaseController 'temp_id', 'remark', ]); - if (!$data['from_name'] || + if ( + !$data['from_name'] || !$data['delivery_name'] || !$data['from_tel'] || !$data['from_addr'] || @@ -186,7 +186,7 @@ class Order extends BaseController 'delivery_type', 'station_id', 'mark', - ['cargo_weight',0], + ['cargo_weight', 0], 'remark', ]); if ($data['cargo_weight'] < 0) return app('json')->fail('包裹重量能为负数'); @@ -206,7 +206,7 @@ class Order extends BaseController $method = 'delivery'; break; } - $this->repository->runDelivery($id,$this->request->merId(), $data, $split, $method); + $this->repository->runDelivery($id, $this->request->merId(), $data, $split, $method); return app('json')->success('发货成功'); } @@ -295,7 +295,7 @@ class Order extends BaseController public function status($id) { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['date','user_type']); + $where = $this->request->params(['date', 'user_type']); $where['id'] = $id; if (!$this->repository->getOne($id, $this->request->merId())) return app('json')->fail('数据不存在'); @@ -337,7 +337,7 @@ class Order extends BaseController */ public function verify($id) { - $data = $this->request->params(['data','verify_code']); + $data = $this->request->params(['data', 'verify_code']); $this->repository->verifyOrder($id, $this->request->merId(), $data); return app('json')->success('订单核销成功'); } @@ -349,6 +349,16 @@ class Order extends BaseController return app('json')->success($order); } + /** + * 生成取货码 + */ + public function logisticsCode($id) + { + $order = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $this->request->merId(), 'is_del' => 0]); + if (!$order) + return app('json')->fail('订单状态有误'); + return app('json')->success(['qrcode' => $this->repository->logisticsQrcode($id, $order->order_sn)]); + } /** * @param $id * @return mixed @@ -424,7 +434,7 @@ class Order extends BaseController unset($where['order_type']); } $where['mer_id'] = $this->request->merId(); - $data = app()->make(ExcelService::class)->order($where,$page,$limit); + $data = app()->make(ExcelService::class)->order($where, $page, $limit); return app('json')->success($data); } @@ -462,7 +472,7 @@ class Order extends BaseController if (!$count) return app('json')->fail('没有可导出数据'); [$page, $limit] = $this->getPage(); - $data = app()->make(ExcelService::class)->delivery($where,$page,$limit); + $data = app()->make(ExcelService::class)->delivery($where, $page, $limit); return app('json')->success($data); } diff --git a/route/merchant/order.php b/route/merchant/order.php index 75480e02..6f96dcf9 100644 --- a/route/merchant/order.php +++ b/route/merchant/order.php @@ -109,6 +109,9 @@ Route::group(function () { Route::get('children/:id', 'Order/childrenList')->name('merchantStoreOrderChildrenList')->option([ '_alias' => '关联订单', ]); + Route::get('logistics_code/:id', 'Order/logisticsCode')->name('merchantStoreOrderLogisticsCode')->option([ + '_alias' => '生成取货码', + ]); })->prefix('merchant.store.order.')->option([ '_path' => '/order/list', '_auth' => true, From 20c959aa98c3dec9ece1512ca7ecc06071a64b40 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 23 Nov 2023 11:13:22 +0800 Subject: [PATCH 15/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E6=88=B7?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/mer.html | 2 +- ...{chunk-bab0b9dc.3708b44a.css => chunk-1888ff3b.1f7dc55b.css} | 2 +- ...{chunk-4dbe6a20.4b7aa80e.css => chunk-4517b48f.f0be6af3.css} | 2 +- public/mer/js/{app.6f011970.js => app.6b0c0074.js} | 2 +- public/mer/js/chunk-09296115.1e8c40a4.js | 1 - public/mer/js/chunk-09296115.db61796a.js | 1 + public/mer/js/chunk-1888ff3b.6fadce0b.js | 1 + public/mer/js/chunk-4517b48f.6d9447f5.js | 1 + .../{chunk-4a9f6d94.11ae2226.js => chunk-4a9f6d94.4c4f1045.js} | 2 +- public/mer/js/chunk-4dbe6a20.0febd519.js | 1 - .../{chunk-4f7a44e8.4954143d.js => chunk-4f7a44e8.a49df61c.js} | 2 +- .../{chunk-5310352e.72571813.js => chunk-5310352e.985337f1.js} | 2 +- .../{chunk-67e1db22.abd27fd8.js => chunk-67e1db22.a4951286.js} | 2 +- .../{chunk-6c88f67a.49ca2cb5.js => chunk-6c88f67a.2698795e.js} | 2 +- .../{chunk-7288b5a6.d553c60c.js => chunk-7288b5a6.15bbab90.js} | 2 +- .../{chunk-7788e6ba.14f30dca.js => chunk-7788e6ba.9594c4a0.js} | 2 +- public/mer/js/chunk-ab3d6574.00593e1e.js | 1 + public/mer/js/chunk-ab3d6574.37409ec9.js | 1 - .../{chunk-ae0b147e.6d857c9b.js => chunk-ae0b147e.a63fb860.js} | 2 +- public/mer/js/chunk-bab0b9dc.8e77d0e4.js | 1 - .../js/{chunk-commons.50cf883d.js => chunk-commons.d4178bc4.js} | 0 .../{chunk-f1874498.cea83324.js => chunk-f1874498.bdc2b293.js} | 2 +- 22 files changed, 17 insertions(+), 17 deletions(-) rename public/mer/css/{chunk-bab0b9dc.3708b44a.css => chunk-1888ff3b.1f7dc55b.css} (53%) rename public/mer/css/{chunk-4dbe6a20.4b7aa80e.css => chunk-4517b48f.f0be6af3.css} (81%) rename public/mer/js/{app.6f011970.js => app.6b0c0074.js} (99%) delete mode 100644 public/mer/js/chunk-09296115.1e8c40a4.js create mode 100644 public/mer/js/chunk-09296115.db61796a.js create mode 100644 public/mer/js/chunk-1888ff3b.6fadce0b.js create mode 100644 public/mer/js/chunk-4517b48f.6d9447f5.js rename public/mer/js/{chunk-4a9f6d94.11ae2226.js => chunk-4a9f6d94.4c4f1045.js} (75%) delete mode 100644 public/mer/js/chunk-4dbe6a20.0febd519.js rename public/mer/js/{chunk-4f7a44e8.4954143d.js => chunk-4f7a44e8.a49df61c.js} (77%) rename public/mer/js/{chunk-5310352e.72571813.js => chunk-5310352e.985337f1.js} (64%) rename public/mer/js/{chunk-67e1db22.abd27fd8.js => chunk-67e1db22.a4951286.js} (69%) rename public/mer/js/{chunk-6c88f67a.49ca2cb5.js => chunk-6c88f67a.2698795e.js} (85%) rename public/mer/js/{chunk-7288b5a6.d553c60c.js => chunk-7288b5a6.15bbab90.js} (59%) rename public/mer/js/{chunk-7788e6ba.14f30dca.js => chunk-7788e6ba.9594c4a0.js} (60%) create mode 100644 public/mer/js/chunk-ab3d6574.00593e1e.js delete mode 100644 public/mer/js/chunk-ab3d6574.37409ec9.js rename public/mer/js/{chunk-ae0b147e.6d857c9b.js => chunk-ae0b147e.a63fb860.js} (54%) delete mode 100644 public/mer/js/chunk-bab0b9dc.8e77d0e4.js rename public/mer/js/{chunk-commons.50cf883d.js => chunk-commons.d4178bc4.js} (100%) rename public/mer/js/{chunk-f1874498.cea83324.js => chunk-f1874498.bdc2b293.js} (71%) diff --git a/public/mer.html b/public/mer.html index 9f20a701..dbadc234 100644 --- a/public/mer.html +++ b/public/mer.html @@ -1 +1 @@ -