diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index 2f2b7b93..2af13bd7 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -72,7 +72,7 @@ class StoreOrderDao extends BaseDao if (isset($where['is_trader']) && $where['is_trader'] !== '') { $query->where('is_trader', $where['is_trader']); } - $query->where('is_del',0); + $query->where('is_del', 0); }); $query->when(($sysDel !== null), function ($query) use ($sysDel) { @@ -81,9 +81,9 @@ class StoreOrderDao extends BaseDao ->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) { if ($where['order_type'] == 2) { $query->where('is_virtual', 1); - } else if($where['order_type'] == 0){ //实体发货订单 - $query->where('order_type', 0)->where('is_virtual',0); - } else if($where['order_type'] == 3) { //发货订单 + } else if ($where['order_type'] == 0) { //实体发货订单 + $query->where('order_type', 0)->where('is_virtual', 0); + } else if ($where['order_type'] == 3) { //发货订单 $query->where('order_type', 0); } else { $query->where('order_type', $where['order_type']); @@ -98,19 +98,19 @@ class StoreOrderDao extends BaseDao ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) { // 12表示信用购 先货后款 switch ($where['status']) { - case 0 : + case 0: $query->whereIn('StoreOrder.status', [0, 9, 12]); break; - case -2 : + case -2: $query->where('StoreOrder.paid', 1)->whereNotIn('StoreOrder.status', [10, 11]); break; - case 10 : + case 10: $query->where('StoreOrder.paid', 1)->whereIn('StoreOrder.status', [10, 11]); break; - case 2 : + case 2: $query->where('StoreOrder.paid', 1)->where('StoreOrder.status', $where['status'])->where('pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY); break; - case 20 : + case 20: $query->where('StoreOrder.paid', 1)->whereIn('StoreOrder.status', [2, 3]); break; default: @@ -122,15 +122,15 @@ class StoreOrderDao extends BaseDao $query->where('StoreOrder.uid', $where['uid']); }) ->when(isset($where['is_user']) && $where['is_user'] !== 0, function ($query) use ($where) { - $query->where(function($query) { - $query->where('order_type',0)->whereOr(function($query){ - $query->where('order_type',1)->where('main_id',0); + $query->where(function ($query) { + $query->where('order_type', 0)->whereOr(function ($query) { + $query->where('order_type', 1)->where('main_id', 0); }); }); }) //待核销订单 ->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) { - $query->where('StoreOrder.order_type', 1)->where('StoreOrder.status',0); + $query->where('StoreOrder.order_type', 1)->where('StoreOrder.status', 0); }) ->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) { $query->where('StoreOrder.pay_type', $where['pay_type']); @@ -139,9 +139,9 @@ class StoreOrderDao extends BaseDao $query->whereIn('order_id', $where['order_ids']); }) ->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) { - if(is_array($where['order_id'])){ - $query->whereIn('order_id',$where['order_id']); - }else{ + if (is_array($where['order_id'])) { + $query->whereIn('order_id', $where['order_id']); + } else { $query->where('order_id', $where['order_id']); } }) @@ -154,6 +154,9 @@ class StoreOrderDao extends BaseDao ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) { getModelTime($query, $where['date'], 'StoreOrder.create_time'); }) + ->when(isset($where['pay_time']) && $where['pay_time'] !== '', function ($query) use ($where) { + getModelTime($query, $where['pay_time'], 'StoreOrder.pay_time'); + }) ->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) { getModelTime($query, $where['verify_date'], 'verify_time'); }) @@ -170,40 +173,40 @@ class StoreOrderDao extends BaseDao $query->where('service_id', $where['service_id']); }) ->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) { - $query->join('User U','StoreOrder.uid = U.uid') - ->where(function($query) use($where) { - $query->where('nickname', 'like', "%{$where['username']}%") - ->whereOr('phone', 'like', "%{$where['username']}%") - ->whereOr('user_phone', 'like', "%{$where['username']}%"); + $query->join('User U', 'StoreOrder.uid = U.uid') + ->where(function ($query) use ($where) { + $query->where('nickname', 'like', "%{$where['username']}%") + ->whereOr('phone', 'like', "%{$where['username']}%") + ->whereOr('user_phone', 'like', "%{$where['username']}%"); }); }) ->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) { $orderId = StoreOrderProduct::alias('op') - ->join('storeProduct sp','op.product_id = sp.product_id') - ->whereLike('store_name',"%{$where['store_name']}%") - ->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''),function($query) use($where){ - $query->where('mer_id',$where['mer_id']); + ->join('storeProduct sp', 'op.product_id = sp.product_id') + ->whereLike('store_name', "%{$where['store_name']}%") + ->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) { + $query->where('mer_id', $where['mer_id']); })->column('order_id'); - $query->whereIn('order_id',$orderId ?: '' ); + $query->whereIn('order_id', $orderId ?: ''); }) ->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) { $orderId = StoreOrderProduct::alias('op') - ->join('storeProduct sp','op.product_id = sp.product_id') - ->whereLike('store_name',"%{$where['search']}%") - ->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''),function($query) use($where){ - $query->where('mer_id',$where['mer_id']); + ->join('storeProduct sp', 'op.product_id = sp.product_id') + ->whereLike('store_name', "%{$where['search']}%") + ->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) { + $query->where('mer_id', $where['mer_id']); })->column('order_id'); - $query->where(function($query) use($orderId,$where){ - $query->whereIn('order_id',$orderId ? $orderId : '') - ->whereOr('order_sn','like',"%{$where['search']}%") - ->whereOr('user_phone','like',"%{$where['search']}%"); + $query->where(function ($query) use ($orderId, $where) { + $query->whereIn('order_id', $orderId ? $orderId : '') + ->whereOr('order_sn', 'like', "%{$where['search']}%") + ->whereOr('user_phone', 'like', "%{$where['search']}%"); }); }) ->when(isset($where['order_search']) && $where['order_search'] !== '', function ($query) use ($where) { $query->where('order_sn', 'like', '%' . $where['order_search'] . '%')->whereOr('user_phone', $where['order_search']); }) ->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) { - $query->join('StoreGroupOrder GO','StoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn',$where['group_order_sn']); + $query->join('StoreGroupOrder GO', 'StoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn', $where['group_order_sn']); }) ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) { $query->where(function ($query) use ($where) { @@ -270,8 +273,8 @@ class StoreOrderDao extends BaseDao public function fieldExists($field, $value, ?int $except = null): bool { return ($this->getModel()::getDB())->when($except, function ($query) use ($field, $except) { - $query->where($field, '<>', $except); - })->where($field, $value)->count() > 0; + $query->where($field, '<>', $except); + })->where($field, $value)->count() > 0; } /** @@ -360,15 +363,15 @@ class StoreOrderDao extends BaseDao })->when($date, function ($query, $date) use ($paid) { if (!$paid) { getModelTime($query, $date); -// $query->where(function ($query) use ($date) { -// $query->where(function ($query) use ($date) { -// $query->where('paid', 1); -// getModelTime($query, $date, 'pay_time'); -// })->whereOr(function ($query) use ($date) { -// $query->where('paid', 0); -// getModelTime($query, $date); -// }); -// }); + // $query->where(function ($query) use ($date) { + // $query->where(function ($query) use ($date) { + // $query->where('paid', 1); + // getModelTime($query, $date, 'pay_time'); + // })->whereOr(function ($query) use ($date) { + // $query->where('paid', 0); + // getModelTime($query, $date); + // }); + // }); } else getModelTime($query, $date, 'pay_time'); })->group('uid')->count(); @@ -424,7 +427,7 @@ class StoreOrderDao extends BaseDao public function orderGroupNum($date, $merId = null) { $field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`'); - if ($date == 'year'){ + if ($date == 'year') { $field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m\') as `day`'); } $query = StoreOrder::getDB()->field($field) @@ -440,10 +443,19 @@ class StoreOrderDao extends BaseDao { return StoreOrder::getDB()->when(isset($where['dateRange']), function ($query) use ($where) { getModelTime($query, date('Y/m/d 00:00:00', $where['dateRange']['start']) . '-' . date('Y/m/d 00:00:00', $where['dateRange']['stop']), 'pay_time'); - })->field(Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`')) + })->field( + Db::raw('status,sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`') + ) ->where('paid', 1)->when($merId, function ($query, $merId) { $query->where('mer_id', $merId); - })->order('pay_time DESC')->page($page, $limit)->group('day')->select(); + })->order('pay_time DESC')->page($page, $limit)->group('day')->select()->each(function ($item) use ($merId) { + $pay_time = explode(' ', $item['pay_time']); + $item->settlement_price = Db::name('store_order') + ->whereIn('status', [2, 3]) + ->where('mer_id', $merId) + ->whereDay('pay_time', $pay_time[0]) + ->sum('pay_price'); + }); } public function dayOrderPriceGroup($date, $merId = null) @@ -534,20 +546,20 @@ class StoreOrderDao extends BaseDao * @author Qinii * @day 2020-11-11 */ - public function getTattendCount(array $data,?int $uid) + public function getTattendCount(array $data, ?int $uid) { - $query = StoreOrder::hasWhere('orderProduct',function($query)use($data,$uid){ - $query->when(isset($data['activity_id']),function ($query)use($data){ - $query->where('activity_id',$data['activity_id']); + $query = StoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) { + $query->when(isset($data['activity_id']), function ($query) use ($data) { + $query->where('activity_id', $data['activity_id']); + }) + ->when(isset($data['product_sku']), function ($query) use ($data) { + $query->where('product_sku', $data['product_sku']); }) - ->when(isset($data['product_sku']),function ($query)use($data){ - $query->where('product_sku',$data['product_sku']); + ->when(isset($data['product_id']), function ($query) use ($data) { + $query->where('product_id', $data['product_id']); }) - ->when(isset($data['product_id']),function ($query)use($data){ - $query->where('product_id',$data['product_id']); - }) - ->when(isset($data['exsits_id']),function ($query)use ($data){ - switch ($data['product_type']){ + ->when(isset($data['exsits_id']), function ($query) use ($data) { + switch ($data['product_type']) { case 3: $make = app()->make(ProductAssistSetRepository::class); $id = 'product_assist_id'; @@ -559,34 +571,33 @@ class StoreOrderDao extends BaseDao } $where = [$id => $data['exsits_id']]; $activity_id = $make->getSearch($where)->column($make->getPk()); - if($activity_id) { + if ($activity_id) { $id = array_unique($activity_id); - $query->where('activity_id','in',$id); - }else{ - $query->where('activity_id','<',0); + $query->where('activity_id', 'in', $id); + } else { + $query->where('activity_id', '<', 0); } }) - ->where('product_type',$data['product_type']); - if($uid) $query->where('uid',$uid); + ->where('product_type', $data['product_type']); + if ($uid) $query->where('uid', $uid); }); - $query->where('activity_type',$data['product_type']); - switch($data['product_type']) - { + $query->where('activity_type', $data['product_type']); + switch ($data['product_type']) { case 0: - $query->where(function($query){ - $query->where(function($query){ - $query->where('paid',1); - })->whereOr(function($query){ - $query->where('paid',0)->where('is_del',0); + $query->where(function ($query) { + $query->where(function ($query) { + $query->where('paid', 1); + })->whereOr(function ($query) { + $query->where('paid', 0)->where('is_del', 0); }); }); break; case 1: //秒杀 - $query->where(function($query){ - $query->where(function($query){ - $query->where('paid',1); - })->whereOr(function($query){ - $query->where('paid',0)->where('is_del',0); + $query->where(function ($query) { + $query->where(function ($query) { + $query->where('paid', 1); + })->whereOr(function ($query) { + $query->where('paid', 0)->where('is_del', 0); }); })->when(isset($data['day']), function ($query) use ($data) { $query->whereDay('StoreOrder.create_time', $data['day']); @@ -599,28 +610,28 @@ class StoreOrderDao extends BaseDao * 第二阶段参与人数:支付了第一阶段 */ //第二阶段 - if($data['type'] == 1){ - $query->where(function($query){ - $query->where('paid',1)->whereOr(function($query){ - $query->where('paid',0)->where('is_del',0); + if ($data['type'] == 1) { + $query->where(function ($query) { + $query->where('paid', 1)->whereOr(function ($query) { + $query->where('paid', 0)->where('is_del', 0); }); }); } - if($data['type'] == 2) $query->where('paid',1)->where('status','in',[0,1,2,3,-1]); + if ($data['type'] == 2) $query->where('paid', 1)->where('status', 'in', [0, 1, 2, 3, -1]); break; case 3: //助力 - $query->where(function($query){ - $query->where('paid',1)->whereOr(function($query){ - $query->where('paid',0)->where('is_del',0); + $query->where(function ($query) { + $query->where('paid', 1)->whereOr(function ($query) { + $query->where('paid', 0)->where('is_del', 0); }); }); break; case 4: // - $query->where(function($query){ - $query->where('paid',1)->whereOr(function($query){ - $query->where('paid',0)->where('is_del',0); + $query->where(function ($query) { + $query->where('paid', 1)->whereOr(function ($query) { + $query->where('paid', 0)->where('is_del', 0); }) - ->where('status','>',-1); + ->where('status', '>', -1); }); break; } @@ -637,20 +648,20 @@ class StoreOrderDao extends BaseDao * @author Qinii * @day 2020-10-30 */ - public function getTattendSuccessCount($data,?int $uid) + public function getTattendSuccessCount($data, ?int $uid) { - $query = StoreOrder::hasWhere('orderProduct',function($query)use($data,$uid){ - $query->when(isset($data['activity_id']),function ($query)use($data){ - $query->where('activity_id',$data['activity_id']); + $query = StoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) { + $query->when(isset($data['activity_id']), function ($query) use ($data) { + $query->where('activity_id', $data['activity_id']); + }) + ->when(isset($data['product_sku']), function ($query) use ($data) { + $query->where('product_sku', $data['product_sku']); }) - ->when(isset($data['product_sku']),function ($query)use($data){ - $query->where('product_sku',$data['product_sku']); + ->when(isset($data['product_id']), function ($query) use ($data) { + $query->where('product_id', $data['product_id']); }) - ->when(isset($data['product_id']),function ($query)use($data){ - $query->where('product_id',$data['product_id']); - }) - ->when(isset($data['exsits_id']),function ($query)use ($data){ - switch ($data['product_type']){ + ->when(isset($data['exsits_id']), function ($query) use ($data) { + switch ($data['product_type']) { case 3: $make = app()->make(ProductAssistSetRepository::class); $id = 'product_assist_id'; @@ -662,34 +673,33 @@ class StoreOrderDao extends BaseDao } $where = [$id => $data['exsits_id']]; $activity_id = $make->getSearch($where)->column($make->getPk()); - if($activity_id) { + if ($activity_id) { $id = array_unique($activity_id); - $query->where('activity_id','in',$id); - }else{ - $query->where('activity_id','<',0); + $query->where('activity_id', 'in', $id); + } else { + $query->where('activity_id', '<', 0); } }) - ->where('product_type',$data['product_type']); - if($uid) $query->where('uid',$uid); + ->where('product_type', $data['product_type']); + if ($uid) $query->where('uid', $uid); }); - $query->where('activity_type',$data['product_type'])->where('paid',1); + $query->where('activity_type', $data['product_type'])->where('paid', 1); - switch($data['product_type']) - { + switch ($data['product_type']) { case 1: //秒杀 - $query->where(function($query){ - $query->where(function($query){ - $query->where('paid',1); + $query->where(function ($query) { + $query->where(function ($query) { + $query->where('paid', 1); }); })->when(isset($data['day']), function ($query) use ($data) { $query->whereDay('StoreOrder.create_time', $data['day']); }); break; case 2: //预售 - if($data['type'] == 1){ //第一阶段 - $query->where('status','in',[0,1,2,3,10]); + if ($data['type'] == 1) { //第一阶段 + $query->where('status', 'in', [0, 1, 2, 3, 10]); } else { //第二阶段 - $query->where('status','in',[0,1,2,3]); + $query->where('status', 'in', [0, 1, 2, 3]); } break; case 3: //助力 @@ -708,26 +718,26 @@ class StoreOrderDao extends BaseDao * @author Qinii * @day 1/4/21 */ - public function getSeckillRefundCount($where,$type = 1) + public function getSeckillRefundCount($where, $type = 1) { - $query = StoreOrderProduct::getDB()->alias('P')->join('StoreRefundOrder R','P.order_id = R.order_id'); - $query->join('StoreOrder O','O.order_id = P.order_id'); + $query = StoreOrderProduct::getDB()->alias('P')->join('StoreRefundOrder R', 'P.order_id = R.order_id'); + $query->join('StoreOrder O', 'O.order_id = P.order_id'); $query - ->when(isset($where['activity_id']),function ($query)use($where){ - $query->where('P.activity_id',$where['activity_id']); + ->when(isset($where['activity_id']), function ($query) use ($where) { + $query->where('P.activity_id', $where['activity_id']); }) - ->when(isset($where['product_sku']),function ($query)use($where){ - $query->where('P.product_sku',$where['product_sku']); + ->when(isset($where['product_sku']), function ($query) use ($where) { + $query->where('P.product_sku', $where['product_sku']); }) ->when(isset($where['day']), function ($query) use ($where) { $query->whereDay('P.create_time', $where['day']); }) ->when($type == 1, function ($query) use ($where) { - $query->where('O.verify_time',null)->where('O.delivery_type',null); - },function ($query){ - $query ->where('R.refund_type',2); + $query->where('O.verify_time', null)->where('O.delivery_type', null); + }, function ($query) { + $query->where('R.refund_type', 2); }) - ->where('P.product_type',1)->where('R.status',3); + ->where('P.product_type', 1)->where('R.status', 3); return $query->count(); } @@ -742,14 +752,13 @@ class StoreOrderDao extends BaseDao */ public function getMaxCountNumber(int $uid, int $productId) { - return StoreOrder::hasWhere('orderProduct',function($query) use($productId){ + return StoreOrder::hasWhere('orderProduct', function ($query) use ($productId) { $query->where('product_id', $productId); }) - ->where(function($query) { - $query->where('is_del',0)->whereOr(function($query){ - $query->where('is_del',1)->where('paid',1); - }); - })->where('StoreOrder.uid',$uid)->count() - ; + ->where(function ($query) { + $query->where('is_del', 0)->whereOr(function ($query) { + $query->where('is_del', 1)->where('paid', 1); + }); + })->where('StoreOrder.uid', $uid)->count(); } } 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() { diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 15d9250f..fb700460 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -67,6 +67,7 @@ use think\facade\Log; use think\facade\Queue; use think\facade\Route; use think\Model; +use app\controller\admin\ProductLibrary; /** * Class StoreOrderRepository @@ -143,25 +144,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 +262,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 +291,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 +331,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 +476,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 +553,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 +568,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 +600,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 +608,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 +637,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 +839,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 +859,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 +876,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 +959,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 +1087,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 +1098,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 +1237,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 +1255,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 +1313,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 +1325,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 +1401,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 +1420,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 +1444,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 +1454,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 +1470,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 +1609,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 +1773,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 +1813,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,8 +1999,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) { @@ -2013,7 +2017,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 +2027,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 +2248,6 @@ class StoreOrderRepository extends BaseRepository if (count($couponId)) { app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]); } - } //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); @@ -2292,7 +2294,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 +2478,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(); } @@ -2499,107 +2501,260 @@ class StoreOrderRepository extends BaseRepository * @throws DbException * @throws ModelNotFoundException */ - public function setProduct(array $arrary, $merId) + public function setProduct(array $arrary, $merId,$type_id=0) { //读取excel $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); + // } + // $typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code'); + $product_type = 0; + if ($type_id == 12) { + $product_type = 98; //供应链 } - // $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;//供应链 - } - 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; + try { + foreach ($data as $datum) { + + $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 + ]; } - $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_info" => $datum['value']['store_name'], - "keyword" => $datum['value']['keyword'], - "bar_code" => $datum['value']['bar_code'], - "guarantee_template_id" => "", - "cate_id" => $store_category_id,//要修改 - "mer_cate_id" => [ - 0 => $mer_cate_id//要修改 - ], - 'product_type'=>$product_type, - "unit_name" => $datum['value']['unit_name'], - "sort" => 0, - "is_show" => "", - "is_good" => 0, - "is_gift_bag" => 0, - "integral_rate" => -1, - "video_link" => "", - "temp_id" => "", - "content" => "", - "spec_type" => 0, - "extension_type" => 0, - "attr" => [], - "mer_labels" => [], - "delivery_way" => [ - 0 => "2" - ], - "delivery_free" => 1, - "param_temp_id" => [], - "extend" => [], - "brand_id" => "", - "once_max_count" => 0, - "once_min_count" => 0, - "pay_limit" => 0, - "attrValue" => [ - [ - "image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png", - "price" => $datum['value']['price'], - "cost" => $datum['value']['price'], - "ot_price" => $datum['value']['price'], - "svip_price" => null, - "stock" => $datum['value']['stock'], - "bar_code" => $datum['value']['bar_code'], - "weight" => 0, - "volume" => 0, + $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) { + + $datas['product_id'] = $find['product_id']; + $datas['mer_id'] = $merId; + $datas['store_name'] = $datum['value']['store_name']; + $datas['content'] = 'xls导入商品:已经导入过该规格了'; + $this->create_product_import_log($datas,0); + continue; + } + $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(); + 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]); + $this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, implode(',', $array_values)); + } + $is_update = true; + } else { + $datas = [ + 'product_id' => $find['product_id'], + 'attr_name' => $kk, 'attr_values' => $vv, + ]; + Db::name('store_product_attr')->insert($datas); + } + } + if ($is_update == false) { + $this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, implode(',', $array_values)); + } + } else { + //默认其他分类 + $cate_id = 1726; + $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'); + if ($cate_id_two) { + $cate_id = $cate_id_two; + } + } + /**查询商户分类 */ + $mer_cate_id = 0; + if ($datum['value']['cate_id_one_mer'] != '' && $datum['value']['cate_id_one_two'] != '') { + $cate_id_one_mer = Db::name('store_category')->where('level', 0)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_mer'])->value('store_category_id'); + /**有一级分类 */ + if ($cate_id_one_mer) { + $cate_id_one_two = Db::name('store_category')->where('pid', $cate_id_one_mer)->where('level', 1)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_two'])->value('store_category_id'); + /**有二级分类 */ + if ($cate_id_one_two) { + $mer_cate_id = $cate_id_one_two; + } else { + $mer_cate = ['level' => 1, 'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', '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); + } + } else { + $cate_id_one_mer_arr = ['pid' => 0, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')]; + $cate_id_one_mer = Db::name('store_category')->insertGetId($cate_id_one_mer_arr); + $mer_cate = ['level' => 1, 'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', '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); + } + } + $bar_code = (int) $datum['value']['bar_code']; + $bar_code_where = ['is_used' => 1, 'status' => 1, 'is_del' => 0]; + $bar_code_field = 'id,store_name,bar_code,manu_address,price,stock,image,slider_image,spec,trademark,manu_name,manu_address,note'; + $library = null; + if ($bar_code) { + $library = Db::name('product_library')->where('bar_code', $bar_code)->where($bar_code_where)->field($bar_code_field) + ->withAttr('slider_image', function ($value, $data) { + return $value ? explode(',', $value) : []; + }) + ->find(); + if (!$library) { + $ProductLibrary = app()->make(ProductLibrary::class); + $ProductLibrary->caiji($bar_code); + $library = Db::name('product_library')->where('bar_code', $bar_code)->where($bar_code_where)->field($bar_code_field) + ->withAttr('slider_image', function ($value, $data) { + return $value ? explode(',', $value) : []; + }) + ->find(); + } + } + if ($library) { + $image = $library['image']; + $slider_image = $library['slider_image']; + } else { + $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", + ]; + } + $datas = [ + "image" => $image, + "slider_image" => $slider_image, + "store_name" => $datum['value']['store_name'], + "store_info" => $datum['value']['store_name'], + "keyword" => '', + "bar_code" => $bar_code, + "guarantee_template_id" => "", + "cate_id" => $cate_id, + "mer_cate_id" => [ + 0 => $mer_cate_id ], - ], - "give_coupon_ids" => [], - "type" => 0, - "svip_price" => 0, - "svip_price_type" => 0, - "params" => [], - "mer_id" => $merId, - "status" => 1, - "mer_status" => 1, - "rate" => 3, - ]; - $data_list=[ - 'data'=>$datas, - 'product_type'=>$product_type, - ]; - Queue::push(ProductImportJob::class,$data_list); + 'product_type' => $product_type, + "unit_name" => $datum['value']['unit_name'], + "sort" => 0, + "is_show" => "", + "is_good" => 0, + "is_gift_bag" => 0, + "integral_rate" => -1, + "video_link" => "", + "temp_id" => "", + "content" => "", + "spec_type" => $spec_type, + "extension_type" => 0, + "attr" => $arr, + "mer_labels" => [], + "delivery_way" => [ + 0 => "2", + 1 => "1" + ], + "delivery_free" => 0, + "param_temp_id" => [], + "extend" => [], + "brand_id" => "", + "once_max_count" => 0, + "once_min_count" => 0, + "pay_limit" => 0, + "attrValue" => [ + [ + "image" => $image, + "price" => $datum['value']['price'], + "cost" => $datum['value']['cost'], + "ot_price" => $datum['value']['price'], + "svip_price" => null, + "procure_price" => $datum['value']['procure_price'] ?? 0, + "stock" => 1, + "bar_code" => (int)$datum['value']['bar_code'], + "weight" => 0, + "volume" => 0, + "detail" => $detail, + ], + ], + "give_coupon_ids" => [], + "type" => 0, + "svip_price" => 0, + "svip_price_type" => 0, + "params" => [], + "mer_id" => $merId, + "status" => 1, + "mer_status" => 1, + "rate" => 3, + ]; + // $data_list = [ + // 'data' => $datas, + // 'product_type' => $product_type, + // ]; + $make = app()->make(ProductRepository::class); + $product_id = $make->create($datas, $product_type); + if ($product_id) { + $datas['product_id'] = $product_id; + $datas['mer_id'] = $merId; + $datas['store_name'] = $datum['value']['store_name']; + $this->create_product_import_log($datas); + } + // Queue::push(ProductImportJob::class, $data_list); + } + } + } catch (Exception $e) { + $datas['product_id'] = $product_id??0; + $datas['mer_id'] = $merId; + $datas['store_name'] = $datum['value']['store_name']; + $datas['content'] = $e->getMessage().'line:'.$e->getLine(); + $this->create_product_import_log($datas, 0); } return true; } + public function create_product_import_log($data, $status = 1) + { + $data = [ + 'product_id' => $data['product_id']??0, + 'mer_id' => $data['mer_id'], + 'name' => $data['store_name'], + 'content' => $data['content'] ?? '', + 'status' => $status, + 'create_time' => date('Y-m-d H:i:s'), + ]; + Db::name('store_product_import')->insert($data); + } + 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 @@ -2781,7 +2936,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 +2947,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 +2958,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 fddaa417..245e4a64 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -239,7 +239,9 @@ class ProductRepository extends BaseRepository $result = $this->dao->create($product); $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); - // $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); + if(isset($data['mer_cate_id']) &&$data['mer_cate_id']!=0){ + $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); + } $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); if (in_array($productType, [0, 98, 99])) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [], $data['mer_id']); $this->save($result->product_id, $settleParams, $content, $product, $productType); @@ -284,8 +286,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 +303,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) @@ -829,11 +837,11 @@ class ProductRepository extends BaseRepository break; } if ($productType == 0) { - $where[] = empty($merId) ? ['product_type', 'in', [0, 98, 99]] : ['product_type', 'in', [0]]; + $where['product_type'] = $productType; if (!$merId) $where['is_gift_bag'] = 0; } - if ($productType == 1) { - $where[] = ['product_type', 'in', [$productType]]; + if ($productType == 1 ||$productType==98) { + $where['product_type'] = $productType; } if ($productType == 10) { $where['is_gift_bag'] = 1; 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/controller/admin/ProductLibrary.php b/app/controller/admin/ProductLibrary.php index 969805c1..32ffa8db 100644 --- a/app/controller/admin/ProductLibrary.php +++ b/app/controller/admin/ProductLibrary.php @@ -129,6 +129,7 @@ class ProductLibrary extends BaseController $data['create_time'] = date('Y-m-d H:i:s'); $data['images'] = ''; $arr=[]; + if ($param['img'] != '') { $oss = $upload->to($dir)->stream(file_get_contents($param['img'])); $data['image'] = $oss->filePath; @@ -148,7 +149,7 @@ class ProductLibrary extends BaseController } $data['images'] = ''; $res = Db::name('product_library')->insert($data); - + if ($res) { $group_id=Db::name('system_group')->where('group_key','product_caiji_count')->value('group_id'); if($group_id){ @@ -165,12 +166,11 @@ class ProductLibrary extends BaseController throw new \think\exception\ValidateException('添加失败'); } } else { - - Log::error('商品采集错误:' . $result['message']); - throw new \think\exception\ValidateException($result['message']); + Log::error('一维码商品采集错误:' . $result['data']['remark']); + throw new \think\exception\ValidateException('一维码商品采集错误:'. $result['data']['remark']); } } catch (\Exception $e) { - throw new \think\exception\ValidateException($e->getMessage()); + throw new \think\exception\ValidateException('一维码商品采集错误:'.$e->getMessage()); } } } diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index 96facf9f..4b79b5cd 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -244,7 +244,14 @@ 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')); + $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/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/app/controller/api/Common.php b/app/controller/api/Common.php index 9ff9ec33..01098dcc 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -42,6 +42,7 @@ use crmeb\services\WechatService; use Exception; use Joypack\Tencent\Map\Bundle\Location; use Joypack\Tencent\Map\Bundle\LocationOption; +use Overtrue\Pinyin\Pinyin; use think\exception\ValidateException; use think\facade\Cache; use think\facade\Db; @@ -161,8 +162,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); @@ -485,7 +486,20 @@ class Common extends BaseController //街道 乡镇数据 public function get_street($area_code){ $select=Db::name('geo_street')->where('area_code',$area_code)->field('street_id id,street_code code,street_name name')->select(); - return app('json')->success($select); + $arr=$select?$select->toArray():[]; + foreach ($arr as $k=>$item){ + $first_char = mb_str_split($item['name']); + if($first_char[0]){ + $pinyin=new Pinyin(); + $string=$first_char[0]; + $pinyin = $pinyin->abbr($string); + $arr[$k]['pinyin']=$pinyin; + }else{ + $arr[$k]['pinyin']=''; + } + + } + return app('json')->success($arr); } //村数据 public function get_village($street_code){ diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php new file mode 100644 index 00000000..47dbea2b --- /dev/null +++ b/app/controller/api/Demo.php @@ -0,0 +1,197 @@ + +// +---------------------------------------------------------------------- + + +namespace app\controller\api; + + +use crmeb\basic\BaseController; +use think\facade\Db; +use crmeb\services\UploadService; +use Exception; +use ZipArchive; + +/** + * Class Auth + * @package app\controller\api + * @author xaboy + * @day 2020-05-06 + */ +class Demo extends BaseController +{ + public function index() + { + $mer_id = 65; + $file = request()->file('file'); + $zip_name = explode('.', $file->getOriginalName())[0]; + // 上传到本地服务器 + $savename = \think\facade\Filesystem::putFile('zippic', $file); + $dir = date('Y-m-d_H-i-s') . '_' . $mer_id; + $destination_path = public_path('uploads/pic/' . $dir.'_'.$zip_name); + mkdir($destination_path, 0777, true); + $zipFile = new \PhpZip\ZipFile(); + try { + $zipFile + ->openFile(public_path('uploads').$savename) // open archive from file + ->extractTo($destination_path) // add an entry from the string + // ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files + ->close(); // close archive + } catch (\PhpZip\Exception\ZipException $e) { + throw new \think\exception\HttpException(404,$e->getMessage()); + } finally { + $zipFile->close(); + } + + // if ($zip->open(public_path('uploads').$savename) === TRUE) { + // $zip->extractTo($destination_path); + // $zip->close(); + // } else { + // throw new \think\exception\HttpException(404, '解压失败'); + // } + $directory = $destination_path; + $files = scandir($directory); + $dir = 'def/' . date('Y-m-d'); + $upload = UploadService::create(); + /**循环目录 */ + foreach ($files as $file) { + if ($file === '.' || $file === '..' || $file === '__MACOSX') { + continue; + } + if (!is_dir($directory . '/' . $file)) { + continue; + } + $files_two = scandir($directory . '/' . $file); + + $image_extensions = array('jpg', 'jpeg', 'png'); + $image = ''; + $slider_image = []; + $details = []; + $sku_arr = []; + /**清洗图片 */ + foreach ($files_two as $file_two) { + if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') { + continue; + } + $arr = explode('.', $file_two); + if (in_array($arr[1], $image_extensions)) { + /**首图 */ + $images[] = $file_two; + if ($image == '' && is_numeric($arr[0])) { + $image = $directory . '/' . $file . '/' . $file_two; + continue; + } + /**轮播图 */ + if (is_numeric($arr[0]) && count($slider_image) < 4) { + $slider_image[] = $directory . '/' . $file . '/' . $file_two; + continue; + } + /**详情图 */ + if (is_numeric($arr[0])) { + $details[] = $directory . '/' . $file_two; + continue; + } + /**sku图 */ + $sku = explode('==', $arr[0]); + if ($sku) { + $sku = implode(',', $sku); + $sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two; + } + } + } + $where = ['mer_id' => $mer_id, 'is_del' => 0]; + $update = []; + $update_content['title'] = ''; + $update_content['image'] = []; + $update_content['type'] = 1; + $find = Db::name('store_product')->where($where)->where('store_name', $file)->find(); + if ($find) { + try { + /**更新商品图片 */ + $image = $upload->to($dir)->stream(file_get_contents($image)); + $update['image'] = $image->filePath; + foreach ($slider_image as $k => $v) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + $update['slider_image'][] = $oss->filePath; + } + if (isset($update['slider_image'])) { + $update['slider_image'] = implode(',', $update['slider_image']); + } + Db::name('store_product')->where('product_id', $find['product_id'])->update($update); + /**更新规格图片 */ + foreach ($sku_arr as $k => $v) { + $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); + if ($store_product_attr_value) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + Db::name('store_product_attr_value') + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) + ->update(['image' => $oss->filePath]); + } + } + /**更新详情图片 */ + $store_product_content = Db::name('store_product_content')->where(['product_id' => $find['product_id']])->find(); + foreach ($details as $k => $v) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + $update_content['image'][] = $oss->filePath; + } + if ($store_product_content) { + if (isset($update_content['image']) && !empty($update_content['image'])) { + Db::name('store_product_content') + ->where(['product_id' => $find['product_id']]) + ->update(['content' => json_encode($update_content)]); + } + } else { + $update_content['product_id'] = $find['product_id']; + Db::name('store_product_content') + ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); + } + } catch (Exception $e) { + halt($e->getMessage(), $e->getLine()); + } + } + } + halt(1); + } + + public function transcoding($fileName) + { + $encoding = mb_detect_encoding($fileName, ['UTF-8', 'GBK', 'BIG5', 'CP936']); + if (DIRECTORY_SEPARATOR == '/') { // linux + $fileName = iconv($encoding, 'UTF-8', $fileName); + } else { // win + $fileName = iconv($encoding, 'GBK', $fileName); + } + return $fileName; + } + + function createDirectories($path) { + if (is_dir($path)) { + return true ; + } else { + $parts = explode(DIRECTORY_SEPARATOR, $path); + $part = null; + + foreach ($parts as $part) { + if ($part === '' || $part === '.' || $part === '..') { + continue; + } + + $dir = dirname($path) . DIRECTORY_SEPARATOR . $part; + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + } + + return true ; + } + } + +} diff --git a/app/controller/api/Statistics.php b/app/controller/api/Statistics.php index e94d16d3..b4dcca17 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,53 @@ 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){ + $account[] = ['account', 'in', explode(',', $parmas['phone'])]; + $user_id = Db::name('user')->where($account)->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/app/controller/api/server/StoreOrder.php b/app/controller/api/server/StoreOrder.php index 2bd0992f..49fb89e8 100644 --- a/app/controller/api/server/StoreOrder.php +++ b/app/controller/api/server/StoreOrder.php @@ -70,6 +70,7 @@ class StoreOrder extends BaseController { [$page, $limit] = $this->getPage(); $where['status'] = $this->request->param('status'); + $where['pay_time'] = $this->request->param('pay_time'); $where['product_type'] = $this->request->param('product_type',0); if ($where['product_type']==0){ unset($where['product_type']); diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 24ba3c60..f210075a 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)) @@ -135,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('编辑失败'); + } } /** @@ -167,7 +174,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 +201,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 +246,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('入库失败'); } } - } diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 86f321a8..b812fc36 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -56,9 +56,9 @@ class MerchantIntention extends BaseController if ($intentionInfo) { throw new ValidateException('此统一社会信用代码已申请商户'); } - $merInfo = Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->find(); + $merInfo = Db::name('merchant_intention')->where('uid', $this->userInfo->uid)->where('status', 'in',[0,1])->where('is_del',0)->find(); if ($merInfo) { - throw new ValidateException('该用户已存在商户,不可申请'); + throw new ValidateException('该用户已申请商户,不可重复申请'); } $make = app()->make(MerchantRepository::class); if ($make->fieldExists('mer_name', $data['mer_name'])) @@ -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() @@ -341,8 +345,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 +364,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/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index e2920a2f..be5d6d02 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -39,64 +39,15 @@ class CloudWarehouse extends BaseController $this->spuRepository->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null; } - /** - * 指定类型的云仓商品列表 - * @return mixed - */ - // public function index() - // { - // // 除了市级供应链都可以查询 - // $typeIdArray = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypePlatform'])->column('mer_type_id'); - // $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword','page_num']); - // $search = [ - // // 'street_id' => $params['street_code'], - // 'type_id' => $typeIdArray ?? [], - // 'status' => 1, - // 'is_del' => 0, - // 'mer_state' => 1, - // ]; - // if (!empty($params['category_id'])) { - // $search['category_id'] = $params['category_id']; - // } - // $merchantIds = $this->merchantDao->search($search)->column('mer_id'); - // [$page, $limit] = $this->getPage(); - // if(isset($params['page_num'])&&$params['page_num']!=''){ - // $page=$params['page_num']; - // } - // if (empty($merchantIds)) { - // return app('json')->success(['count' => 0, 'list' => []]); - // } - // // 隐藏镇级云仓 - // // $typeCloudWarehouseId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeCloudWarehouse'])->value('mer_type_id'); - // // $entryWhere = [ - // // 'street_id' => $params['street_code'], - // // 'type_id' => $typeCloudWarehouseId, - // // 'status' => 1, - // // 'is_del' => 0, - // // 'mer_state' => 1, - // // ]; - // // if (!empty($params['category_id'])) { - // // $entryWhere['category_id'] = $params['category_id']; - // // } - // // $where['entry_mer_id'] = $this->merchantDao->search($entryWhere)->value('mer_id'); - - // $where['entry_mer_id'] = 0; - // $where['keyword'] = $params['keyword']; - // $where['mer_ids'] = $merchantIds; - // $where['product_type'] = $params['product_type']; - // $where['is_gift_bag'] = 0; - // $where['order'] = $params['order'] ?: 'sort'; - // $products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false); - // return app('json')->success($products); - // } - /** * type_id 13云仓商品列表 * @return mixed */ public function index($street_code, $page = 1, $category_id = 0,$location='') { - $cloud_product = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->page($page)->column('product_id'); + $cloud_product = Db::name('cloud_product') + ->where('cate_id',$category_id) + ->where('street_code', $street_code)->where('status', 1)->page($page)->column('product_id'); $where = [ 'is_show' => 1, 'is_used' => 1, @@ -107,11 +58,10 @@ class CloudWarehouse extends BaseController 'product_id'=>$cloud_product ]; if (!$cloud_product && $category_id==0) { - return app('json')->success(['count' => 0, 'list' => []]); } $count = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->count(); - + $products = $this->spuRepository->getApiSearch($where,$page,10, false,true); if($products['list']){ $list=$products['list']; @@ -128,14 +78,12 @@ class CloudWarehouse extends BaseController $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword', 'page']); $search = [ 'street_id' => $params['street_code'], - 'type_id' => Merchant::TypeTownSupplyChain, + 'type_id' =>[Merchant::TypeStore,Merchant::TypeTownSupplyChain], 'status' => 1, 'is_del' => 0, 'mer_state' => 1, ]; - if (!empty($params['category_id'])) { - $search['category_id'] = $params['category_id']; - } + $merchantIds = $this->merchantDao->search($search)->column('mer_id'); [$page, $limit] = $this->getPage(); if (isset($params['page']) && $params['page'] != '') { @@ -150,6 +98,9 @@ class CloudWarehouse extends BaseController $where['product_type'] = $params['product_type']; $where['is_gift_bag'] = 0; $where['order'] = $params['order'] ?: 'sort'; + if (!empty($params['category_id'])) { + $where['cate_id'] = $params['category_id']; + } $products = $this->spuRepository->getApiSearch($where, $page, $limit, false,true); return app('json')->success($products); } 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/app/controller/merchant/store/StoreImport.php b/app/controller/merchant/store/StoreImport.php index 19214971..be0c08b3 100644 --- a/app/controller/merchant/store/StoreImport.php +++ b/app/controller/merchant/store/StoreImport.php @@ -15,13 +15,14 @@ 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\jobs\ImportPicJob; 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 ZipArchive; use think\facade\Db; use think\facade\Queue; @@ -72,13 +73,16 @@ class StoreImport extends BaseController } /** - * TODO 导入excel信息 + * TODO 导入excel商品信息 * @return \think\response\Json * @author Qinii * @day 3/16/21 */ public function Import($type) { + if($type=='import_images'){ + return $this->import_images(); + } $file = $this->request->file('file'); if (!$file) return app('json')->fail('请上传EXCEL文件'); $file = is_array($file) ? $file[0] : $file; @@ -89,29 +93,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 +162,136 @@ class StoreImport extends BaseController } return app('json')->fail('数据类型错误'); } + + /** + * 导入商品图片 + */ + public function import_images(){ + $file = request()->file('file'); + $zip_name = explode('.', $file->getOriginalName())[0]; + // 上传到本地服务器 + $savename = \think\facade\Filesystem::putFile('zippic', $file); + $mer_id = $this->request->merId(); + $dir = date('Y-m-d_H-i-s') . '_' . $mer_id; + $path = public_path('uploads/pic').$dir; + try { + $zip = new ZipArchive; + $filePath = public_path('uploads') . $savename; + $zip->open($filePath); + for ($i = 0; $i < $zip->numFiles; $i++) { + $statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW); + $filename = $this->transcoding($statInfo['name']); + $mkdFile = explode('/',$filename); + if ($statInfo['crc'] == 0) { + // 新建目录 + if (!file_exists($path . '/' . $filename)) { + mkdir($path . '/' . $filename, 0777, true); + } + } else { + // 拷贝文件 + if(count($mkdFile)==3){ + if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) { + mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true); + } + copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename); + } + } + } + $zip->close(); + } catch (\Exception $e) { + throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine()); + } + Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$path.'/'.$zip_name]); + return app('json')->success('开始导入数据,请稍后在列表中查看!,如果未导入请检查格式'); + } + + 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' => ['store_name' => 'A'], + ] + ]; + app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_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' => ['store_name' => 'A'], + ] + ]; + app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_id); + } + } + public function transcoding($fileName) + { + $encoding = mb_detect_encoding($fileName, ['UTF-8', 'GBK', 'BIG5', 'CP936']); + if (DIRECTORY_SEPARATOR == '/') { // linux + $fileName = iconv($encoding, 'UTF-8', $fileName); + } else { // win + $fileName = iconv($encoding, 'GBK', $fileName); + } + return $fileName; + } + + function createDirectories($path) { + if (is_dir($path)) { + return true ; + } else { + $parts = explode(DIRECTORY_SEPARATOR, $path); + $part = null; + + foreach ($parts as $part) { + if ($part === '' || $part === '.' || $part === '..') { + continue; + } + + $dir = dirname($path) . DIRECTORY_SEPARATOR . $part; + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + } + + return true ; + } + } } 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/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/app/controller/merchant/store/product/Product.php b/app/controller/merchant/store/product/Product.php index 59b18403..14d05a16 100644 --- a/app/controller/merchant/store/product/Product.php +++ b/app/controller/merchant/store/product/Product.php @@ -55,6 +55,7 @@ class Product extends BaseController $type=$this->request->merchant()['type_id']; $typeCode=Db::name('merchant_type')->where('mer_type_id',$type)->value('type_code'); $product_type=0; + // if ($type==12){ if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ $where['product_type']=98;//供应链 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'], diff --git a/app/listener/ProductCreate.php b/app/listener/ProductCreate.php index 2a775a70..e01782e9 100644 --- a/app/listener/ProductCreate.php +++ b/app/listener/ProductCreate.php @@ -23,7 +23,7 @@ class ProductCreate if (empty($merchant)) { return false; } - if($merchant['type_id']!=Merchant::TypeTownSupplyChain){ + if ($merchant['type_id'] != Merchant::TypeTownSupplyChain) { return false; } // 根据支持同步到云商的商户进行同步操作 @@ -49,17 +49,20 @@ class ProductCreate return false; } //添加到云仓 - $datas=[ - 'product_id'=>$product_id, - 'mer_id'=>$merchant['mer_id'], - 'source_mer_id'=>$cityMerchant['mer_id'], - 'street_code'=>$merchant['street_id'], - 'type_id'=>$merchant['type_id'], - 'category_id'=>$merchant['category_id'], - 'weight'=>1, - 'status'=>1, - 'create_time'=>date('Y-m-d H:i:s'), - ]; - Db::name('cloud_product')->insert($datas); + $find = Db::name('cloud_product')->where('product_id', $product_id)->find(); + if (!$find) { + $datas = [ + 'product_id' => $product_id, + 'mer_id' => $merchant['mer_id'], + 'source_mer_id' => $cityMerchant['mer_id'], + 'street_code' => $merchant['street_id'], + 'type_id' => $merchant['type_id'], + 'category_id' => $merchant['category_id'], + 'weight' => 1, + 'status' => 1, + 'create_time' => date('Y-m-d H:i:s'), + ]; + Db::name('cloud_product')->insert($datas); + } } } 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/composer.json b/composer.json index 6e408bb1..eeb7ca31 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,8 @@ "guzzlehttp/guzzle": "^6.5", "topthink/think-api": "1.0.27", "intervention/image": "^2.7", - "fastknife/ajcaptcha": "^1.2" + "fastknife/ajcaptcha": "^1.2", + "nelexa/zip": "^4.0" }, "require-dev": { "symfony/var-dumper": "^4.2", diff --git a/composer.lock b/composer.lock index dc1399d1..68d601ea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f75dd06462534352b6436e333bd0daeb", + "content-hash": "60838a051e04cfb13dd75049f7540171", "packages": [ { "name": "adbario/php-dot-notation", @@ -2024,6 +2024,69 @@ ], "time": "2022-08-04T09:53:51+00:00" }, + { + "name": "nelexa/zip", + "version": "4.0.2", + "dist": { + "type": "zip", + "url": "https://mirrors.cloud.tencent.com/repository/composer/nelexa/zip/4.0.2/nelexa-zip-4.0.2.zip", + "reference": "88a1b6549be813278ff2dd3b6b2ac188827634a7", + "shasum": "" + }, + "require": { + "ext-zlib": "*", + "php": "^7.4 || ^8.0", + "psr/http-message": "*", + "symfony/finder": "*" + }, + "require-dev": { + "ext-bz2": "*", + "ext-dom": "*", + "ext-fileinfo": "*", + "ext-iconv": "*", + "ext-openssl": "*", + "ext-xml": "*", + "friendsofphp/php-cs-fixer": "^3.4.0", + "guzzlehttp/psr7": "^1.6", + "phpunit/phpunit": "^9", + "symfony/http-foundation": "*", + "symfony/var-dumper": "*", + "vimeo/psalm": "^4.6" + }, + "suggest": { + "ext-bz2": "Needed to support BZIP2 compression", + "ext-fileinfo": "Needed to get mime-type file", + "ext-iconv": "Needed to support convert zip entry name to requested character encoding", + "ext-openssl": "Needed to support encrypt zip entries or use ext-mcrypt" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpZip\\": "src/" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ne-Lexa", + "email": "alexey@nelexa.ru", + "role": "Developer" + } + ], + "description": "PhpZip is a php-library for extended work with ZIP-archives. Open, create, update, delete, extract and get info tool. Supports appending to existing ZIP files, WinZip AES encryption, Traditional PKWARE Encryption, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.", + "homepage": "https://github.com/Ne-Lexa/php-zip", + "keywords": [ + "archive", + "extract", + "unzip", + "winzip", + "zip", + "ziparchive" + ], + "time": "2022-06-17T11:17:46+00:00" + }, { "name": "nesbot/carbon", "version": "2.71.0", 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, 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'], //驱动模式 diff --git a/crmeb/jobs/ImportPicJob.php b/crmeb/jobs/ImportPicJob.php new file mode 100644 index 00000000..dce0d55c --- /dev/null +++ b/crmeb/jobs/ImportPicJob.php @@ -0,0 +1,148 @@ +attempts()); + if ($job->attempts() > 3) { + $job->delete(); + $this->failed($data); + } + $directory = $data['path']; + $mer_id = $data['mer_id']; + $files = scandir($directory); + $dir = 'def/' . date('Y-m-d'); + $upload = UploadService::create(); + try { + /**循环目录 */ + foreach ($files as $file) { + if ($file === '.' || $file === '..' || $file === '__MACOSX') { + continue; + } + if (!is_dir($directory . '/' . $file)) { + continue; + } + $files_two = scandir($directory . '/' . $file); + + $image_extensions = array('jpg', 'jpeg', 'png'); + $image = ''; + $slider_image = []; + $details = []; + $sku_arr = []; + /**清洗图片 */ + foreach ($files_two as $file_two) { + if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') { + continue; + } + $arr = explode('.', $file_two); + if (in_array($arr[1], $image_extensions)) { + /**首图 */ + $images[] = $file_two; + if ($image == '' && is_numeric($arr[0])) { + $image = $directory . '/' . $file . '/' . $file_two; + continue; + } + /**轮播图 */ + if (is_numeric($arr[0]) && count($slider_image) < 4) { + $slider_image[] = $directory . '/' . $file . '/' . $file_two; + continue; + } + /**详情图 */ + if (is_numeric($arr[0])) { + $details[] = $directory . '/' . $file_two; + continue; + } + /**sku图 */ + $sku = explode('==', $arr[0]); + if ($sku) { + $sku = implode(',', $sku); + $sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two; + } + } + } + $where = ['mer_id' => $mer_id, 'is_del' => 0]; + $update = []; + $update_content['title'] = ''; + $update_content['image'] = []; + $find = Db::name('store_product')->where($where)->where('store_name', $file)->find(); + if ($find) { + /**更新商品图片 */ + $image = $upload->to($dir)->stream(file_get_contents($image)); + $update['image'] = $image->filePath; + foreach ($slider_image as $k => $v) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + $update['slider_image'][] = $oss->filePath; + } + if (isset($update['slider_image'])) { + $update['slider_image'] = implode(',', $update['slider_image']); + } + Db::name('store_product')->where('product_id', $find['product_id'])->update($update); + /**更新规格图片 */ + foreach ($sku_arr as $k => $v) { + $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); + if ($store_product_attr_value) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + Db::name('store_product_attr_value') + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) + ->update(['image' => $oss->filePath]); + } + } + /**更新详情图片 */ + $store_product_content = Db::name('store_product_content')->where(['product_id' => $find['product_id']])->find(); + foreach ($details as $k => $v) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + $update_content['image'][] = $oss->filePath; + } + if ($store_product_content) { + if (isset($update_content['image']) && !empty($update_content['image'])) { + Db::name('store_product_content') + ->where(['product_id' => $find['product_id']]) + ->update(['content' => json_encode($update_content)]); + } + } else { + $update_content['product_id'] = $find['product_id']; + Db::name('store_product_content') + ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); + } + } + } + } catch (Exception $e) { + $data['product_id'] = $find['product_id']; + $data['mer_id'] = $data['mer_id']; + $data['store_name'] = $find['store_name']; + $data['content'] = $e->getMessage(); + $this->create_product_import_log($data, 0); + } + + $job->delete(); + } + + public function failed($data) + { + Log::error('导入商品图片失败:' . json_encode($data)); + // TODO: Implement failed() method. + } + + public function create_product_import_log($data, $status = 1) + { + $data = [ + 'product_id' => $data['product_id'], + 'mer_id' => $data['mer_id'], + 'name' => $data['store_name'], + 'content' => $data['content'] ?? '', + 'status' => $status, + 'create_time' => date('Y-m-d H:i:s'), + ]; + Db::name('store_product_import')->insert($data); + } +} 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();//取得总行数 diff --git a/public/mer.html b/public/mer.html index 9f20a701..93ca96a2 100644 --- a/public/mer.html +++ b/public/mer.html @@ -1 +1 @@ -