This commit is contained in:
mkm 2023-11-21 16:20:48 +08:00
parent 9b5ed65ae9
commit 33e96588a3
7 changed files with 239 additions and 291 deletions

View File

@ -143,25 +143,25 @@ class StoreOrderRepository extends BaseRepository
throw new ValidateException('未开启余额支付');
if ($user['now_money'] < $groupOrder['pay_price'])
throw new ValidateException('余额不足,请更换支付方式');
Db::startTrans();
try{
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
$user->save();
$userBillRepository = app()->make(UserBillRepository::class);
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
'link_id' => $groupOrder['group_order_id'],
'status' => 1,
'title' => '购买商品',
'number' => $groupOrder['pay_price'],
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
'balance' => $user->now_money
]);
$this->paySuccess($groupOrder);
Db::commit();
}catch (Exception $e) {
Db::rollback();
throw new ValidateException('余额支付失败');
}
Db::startTrans();
try {
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
$user->save();
$userBillRepository = app()->make(UserBillRepository::class);
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
'link_id' => $groupOrder['group_order_id'],
'status' => 1,
'title' => '购买商品',
'number' => $groupOrder['pay_price'],
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
'balance' => $user->now_money
]);
$this->paySuccess($groupOrder);
Db::commit();
} catch (Exception $e) {
Db::rollback();
throw new ValidateException('余额支付失败');
}
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
}
@ -261,15 +261,14 @@ class StoreOrderRepository extends BaseRepository
if ($order->activity_type == 99) {
$cartIdArray = explode(',', $order->cart_id);
$ecartList = Db::name('store_cart')->whereIn('cart_id', $cartIdArray)->select();
foreach($ecartList as $ecart) {
foreach ($ecartList as $ecart) {
if (!empty($ecart['source_id'])) {
Db::name('community')->where('community_id', $ecart['source_id'])->update(['entrust_order_id' => $order->order_id ?? 0]);
}
}
}
// 订单的类型 0 发货 1 自提
if ($order->order_type == 1 && $order->status != 10)
{
if ($order->order_type == 1 && $order->status != 10) {
$order->verify_code = $this->verifyCode();
}
$order->save();
@ -291,13 +290,12 @@ class StoreOrderRepository extends BaseRepository
$flag = false;
}
}
if ($order->order_type == 0)
{
if ($order->order_type == 0) {
//发起队列物流信息处理
//event('order.sendGoodsCode', $order);
Queue::push(SendGoodsCodeJob::class, $order);
}
// 商户流水账单数据
$finance[] = [
'order_id' => $order->order_id,
@ -332,9 +330,8 @@ class StoreOrderRepository extends BaseRepository
$_order_rate = bcmul($_payPrice, $commission_rate, 2);
$_payPrice = bcsub($_payPrice, $_order_rate, 2);
// 结算各镇 小组佣金
event('order.paySuccessOrder', compact('order','_order_rate'));
// 结算各镇 小组佣金
event('order.paySuccessOrder', compact('order', '_order_rate'));
}
if (!$presell) {
@ -478,14 +475,14 @@ class StoreOrderRepository extends BaseRepository
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]);
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]);
app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id);
$groupOrder=$groupOrder->toArray();
$groupOrder = $groupOrder->toArray();
event('order.paySuccess', compact('groupOrder'));
//店内扫码支付
if (isset($groupOrder['micro_pay']) && $groupOrder['micro_pay'] == 1) {
$order = $this->dao->search(['uid' => $groupOrder->uid])->where('group_order_id', $groupOrder->group_order_id)->find();
$order->status = 2;
$order->verify_time = date('Y-m-d H:i:s');
$user=$order->user;
$user = $order->user;
event('order.take.before', compact('order'));
Db::transaction(function () use ($order, $user) {
$this->takeAfter($order, $user);
@ -555,7 +552,7 @@ class StoreOrderRepository extends BaseRepository
return $cart['productAssistAttr']['assist_price'];
} else if ($cart['product_type'] == '4') {
return $cart['activeSku']['active_price'];
// 更新调货价格
// 更新调货价格
} else if ($cart['product_type'] == '98') {
// if ($cart['source_id'] > 0) {
// $resale_find = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->find();
@ -570,12 +567,12 @@ class StoreOrderRepository extends BaseRepository
// } else {
// return $cart['productAttr']['price'];
// }
if($cart['source']== StoreCartDao::SOURCE_PROCURE){
if ($cart['source'] == StoreCartDao::SOURCE_PROCURE) {
return $cart['productAttr']['procure_price'];
}else{
} else {
return $cart['productAttr']['price'];
}
// 更新委托价格
// 更新委托价格
} else if ($cart['product_type'] == '99') {
if ($cart['source_id'] > 0) {
$price = Db::name('entrust')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
@ -602,7 +599,7 @@ class StoreOrderRepository extends BaseRepository
return 0;
} else if ($cart['product_type'] == '4') {
return 0;
// 更新调货价格
// 更新调货价格
} else if ($cart['product_type'] == '98') {
$price = Db::name('resale')->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
if ($price) {
@ -610,7 +607,7 @@ class StoreOrderRepository extends BaseRepository
} else {
return $cart['productAttr']['price'];
}
// 更新委托价格
// 更新委托价格
} else if ($cart['product_type'] == '99') {
$price = Db::name('entrust')->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
if ($price) {
@ -639,7 +636,7 @@ class StoreOrderRepository extends BaseRepository
* @author xaboy
* @day 2020/6/10
*/
public function userOrderNumber(int $uid, $product_type=0)
public function userOrderNumber(int $uid, $product_type = 0)
{
//activity_type0普通订单 98采购订单 99委托商品
//$noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid, $product_type);
@ -841,14 +838,14 @@ class StoreOrderRepository extends BaseRepository
if ($order['status'] != 1 || $order['order_type'])
throw new ValidateException('订单状态有误');
$func = 'createUserLog';
if (!$user){
if (!$user) {
$func = 'createSysLog';
$user = $order->user;
}
// if (!$user) {
//
// throw new ValidateException('用户不存在');
// }
// if (!$user) {
//
// throw new ValidateException('用户不存在');
// }
$order->status = 2;
$order->verify_time = date('Y-m-d H:i:s');
event('order.take.before', compact('order'));
@ -861,7 +858,7 @@ class StoreOrderRepository extends BaseRepository
'change_message' => '已收货',
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE,
];
Db::transaction(function () use ($order, $user,$storeOrderStatusRepository,$orderStatus,$func) {
Db::transaction(function () use ($order, $user, $storeOrderStatusRepository, $orderStatus, $func) {
$this->takeAfter($order, $user);
$order->save();
$storeOrderStatusRepository->{$func}($orderStatus);
@ -878,14 +875,14 @@ class StoreOrderRepository extends BaseRepository
* @param int|null $orderType
* @return array
*/
public function OrderTitleNumber(?int $merId, ?int $orderType, ?int $product_type=0)
public function OrderTitleNumber(?int $merId, ?int $orderType, ?int $product_type = 0)
{
$where = [];
$sysDel = $merId ? 0 : null; //商户删除
if ($merId) $where['mer_id'] = $merId; //商户订单
if ($orderType === 0) $where['order_type'] = 0; //普通订单
if ($orderType === 1) $where['take_order'] = 1; //已核销订单
if ($product_type!=0) $where['product_type'] = $product_type; //商品属性
if ($product_type != 0) $where['product_type'] = $product_type; //商品属性
//1: 未支付 2: 未发货 3: 待收货 4: 待评价 5: 交易完成 6: 已退款 7: 已删除 8: 已支付
$all = $this->dao->search($where, $sysDel)->where($this->getOrderType(0))->count();
$statusAll = $all;
@ -961,7 +958,7 @@ class StoreOrderRepository extends BaseRepository
$param['StoreOrder.paid'] = 1;
break; // 已支付
case 20:
$param['StoreOrder.status'] =[2,3];
$param['StoreOrder.status'] = [2, 3];
break; // 已收货的商品才可以继续导入
default:
unset($param['StoreOrder.is_del']);
@ -1089,7 +1086,7 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CHANGE,
];
Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group,$storeOrderStatusRepository,$orderStatus,$service_id) {
Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group, $storeOrderStatusRepository, $orderStatus, $service_id) {
$orderGroup->total_price = $_group['total_price'];
$orderGroup->pay_price = $_group['pay_price'];
$orderGroup->pay_postage = $_group['pay_postage'];
@ -1100,7 +1097,7 @@ class StoreOrderRepository extends BaseRepository
$this->changOrderProduct($id, $data);
if ($service_id) {
$storeOrderStatusRepository->createServiceLog($service_id,$orderStatus);
$storeOrderStatusRepository->createServiceLog($service_id, $orderStatus);
} else {
$storeOrderStatusRepository->createAdminLog($orderStatus);
}
@ -1239,7 +1236,7 @@ class StoreOrderRepository extends BaseRepository
'mer_id' => $merId
];
if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0 ) {
if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0) {
$imp['status'] = 0;
$imp['mark'] = '订单信息不存在或状态错误';
} else {
@ -1257,7 +1254,7 @@ class StoreOrderRepository extends BaseRepository
$imp['delivery_id'] = $ret['delivery_id'];
$imp['delivery_name'] = $ret['delivery_name'];
} else {
$this->delivery($item, $merId,[
$this->delivery($item, $merId, [
'delivery_id' => $params['delivery_id'],
'delivery_type' => $params['delivery_type'],
'delivery_name' => $params['delivery_name'],
@ -1315,7 +1312,7 @@ class StoreOrderRepository extends BaseRepository
'to_name' => $data['to_name'],
];
Db::transaction(function () use ($merId, $id, $delivery, $make, $dump, $service_id) {
$this->delivery($id, $merId, $delivery,$service_id);
$this->delivery($id, $merId, $delivery, $service_id);
$arr = [
'type' => 'mer_dump',
'num' => -1,
@ -1327,22 +1324,22 @@ class StoreOrderRepository extends BaseRepository
return $delivery;
}
public function runDelivery($id, $merId, $data, $split, $method,$service_id = 0)
public function runDelivery($id, $merId, $data, $split, $method, $service_id = 0)
{
return Db::transaction(function () use ($id, $merId, $data, $split, $method,$service_id) {
return Db::transaction(function () use ($id, $merId, $data, $split, $method, $service_id) {
if ($split['is_split'] && !empty($split['split'])) {
foreach ($split['split'] as $v) {
$splitData[$v['id']] = $v['num'];
}
$order = $this->dao->get($id);
$newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData,$service_id);
if ($newOrder){
$newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData, $service_id);
if ($newOrder) {
$id = $newOrder->order_id;
} else {
throw new ValidateException('商品不能全部拆单');
}
}
return $this->{$method}($id, $merId, $data,$service_id);
return $this->{$method}($id, $merId, $data, $service_id);
});
}
@ -1403,17 +1400,17 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $change_type,
];
if ($service_id) {
$statusRepository->createServiceLog($service_id,$orderStatus);
$statusRepository->createServiceLog($service_id, $orderStatus);
} else {
$statusRepository->createAdminLog($orderStatus);
}
//虚拟发货后用户直接确认收获
if($data['status'] == 2){
if ($data['status'] == 2) {
$user = app()->make(UserRepository::class)->get($order['uid']);
//订单记录
$this->takeAfter($order,$user);
$this->takeAfter($order, $user);
$orderStatus = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
@ -1422,7 +1419,6 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $statusRepository::ORDER_STATUS_TAKE,
];
$statusRepository->createSysLog($orderStatus);
}
if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]);
@ -1447,7 +1443,7 @@ class StoreOrderRepository extends BaseRepository
$make->create($id, $merId, $data, $order);
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
$this->dao->update($id, ['delivery_type' => 5, 'status' => 1,'remark' => $data['remark']]);
$this->dao->update($id, ['delivery_type' => 5, 'status' => 1, 'remark' => $data['remark']]);
$orderStatus = [
'order_id' => $id,
@ -1457,7 +1453,7 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $storeOrderStatusRepository::ORDER_DELIVERY_SELF,
];
if ($service_id) {
$storeOrderStatusRepository->createServiceLog($service_id,$orderStatus);
$storeOrderStatusRepository->createServiceLog($service_id, $orderStatus);
} else {
$storeOrderStatusRepository->createAdminLog($orderStatus);
}
@ -1473,21 +1469,24 @@ class StoreOrderRepository extends BaseRepository
$whre['mer_id'] = $merId;
$whre['is_system_del'] = 0;
}
$res = $this->dao->getWhere($where, '*', [
'orderProduct',
'user' => function ($query) {
$query->field('uid,real_name,nickname,is_svip,svip_endtime,phone');
},
'refundOrder' => function ($query) {
$query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3);
},
'finalOrder',
'TopSpread' => function ($query) {
$query->field('uid,nickname,avatar');
},
'spread' => function ($query) {
$query->field('uid,nickname,avatar');
},
$res = $this->dao->getWhere(
$where,
'*',
[
'orderProduct',
'user' => function ($query) {
$query->field('uid,real_name,nickname,is_svip,svip_endtime,phone');
},
'refundOrder' => function ($query) {
$query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3);
},
'finalOrder',
'TopSpread' => function ($query) {
$query->field('uid,nickname,avatar');
},
'spread' => function ($query) {
$query->field('uid,nickname,avatar');
},
]
);
if (!$res) throw new ValidateException('数据不存在');
@ -1609,17 +1608,17 @@ class StoreOrderRepository extends BaseRepository
]);
$count = $query->count();
$list = $query->page($page, $limit)->select()->append(['refund_extension_one', 'refund_extension_two'])
->each(function($item){
->each(function ($item) {
// 1:退款中 2:部分退款 3 = 全退
$refunding = 0;
if ($item['orderProduct']) {
$is_refund = array_column($item['orderProduct']->toArray(),'is_refund');
$is_refund = array_column($item['orderProduct']->toArray(), 'is_refund');
$is_refund = array_unique($is_refund);
if (in_array(1,$is_refund)) {
if (in_array(1, $is_refund)) {
$refunding = 1;
} else if (in_array(2,$is_refund)) {
} else if (in_array(2, $is_refund)) {
$refunding = 2;
} else if (in_array(3,$is_refund)) {
} else if (in_array(3, $is_refund)) {
$refunding = 3;
}
}
@ -1773,7 +1772,7 @@ class StoreOrderRepository extends BaseRepository
if ($status == 1) {
$query = $this->dao->search($where)->where($this->getOrderType($status))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where('StoreOrder.is_del', 0);
} else {
$arr=$this->getOrderType($status);
$arr = $this->getOrderType($status);
$query = $this->dao->search($where)->where($arr)->where('StoreOrder.is_del', 0);
}
@ -1813,10 +1812,11 @@ class StoreOrderRepository extends BaseRepository
unset($order['takeOrderList'], $order->interest);
}
return compact( 'count','list');
return compact('count', 'list');
}
public function getOrderStatusV2($order) {
public function getOrderStatusV2($order)
{
//订单状态 1 未支付 2待发货 3待收货 4待评价 5交易完成 6已退款 7待核销 8先货后款待结算 9待商家确认
$order->order_status = 0;
if ($order->paid == 0) {
@ -1998,7 +1998,7 @@ class StoreOrderRepository extends BaseRepository
public function verifyOrder(int $id, int $merId, array $data, $serviceId = 0)
{
$order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId,'verify_code' => $data['verify_code'],'order_type' => 1],'*',['orderProduct']);
$order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']);
if (!$order) throw new ValidateException('订单不存在');
if (!$order->paid) throw new ValidateException('订单未支付');
if ($order['status']) throw new ValidateException('订单已全部核销,请勿重复操作');
@ -2013,7 +2013,7 @@ class StoreOrderRepository extends BaseRepository
event('order.verify.before', compact('order'));
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
Db::transaction(function () use ($order,$storeOrderStatusRepository,$serviceId) {
Db::transaction(function () use ($order, $storeOrderStatusRepository, $serviceId) {
$this->takeAfter($order, $order->user);
$order->save();
$orderStatus = [
@ -2023,12 +2023,11 @@ class StoreOrderRepository extends BaseRepository
'change_message' => '订单已核销',
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE,
];
if ($serviceId){
$storeOrderStatusRepository->createServiceLog($serviceId,$orderStatus);
if ($serviceId) {
$storeOrderStatusRepository->createServiceLog($serviceId, $orderStatus);
} else {
$storeOrderStatusRepository->createAdminLog($orderStatus);
}
});
event('order.verify', compact('order'));
}
@ -2245,7 +2244,6 @@ class StoreOrderRepository extends BaseRepository
if (count($couponId)) {
app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
}
}
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
@ -2292,7 +2290,7 @@ class StoreOrderRepository extends BaseRepository
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_DELETE,
];
$productRepository = app()->make(ProductRepository::class);
Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository,$productRepository) {
Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository, $productRepository) {
$order->is_del = 1;
$order->save();
$storeOrderStatusRepository->createUserLog($orderStatus);
@ -2476,18 +2474,18 @@ class StoreOrderRepository extends BaseRepository
* @author Qinii
* @day 2023/2/22
*/
public function childrenList($id,$merId)
public function childrenList($id, $merId)
{
$data = $this->dao->get($id);
$query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id','<>',$id);
if ($merId) $query->where('mer_id',$merId);
$query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id', '<>', $id);
if ($merId) $query->where('mer_id', $merId);
if ($data['main_id']) {
$query->where(function($query) use($data,$id){
$query->where('main_id',$data['main_id'])->whereOr('order_id',$data['main_id']);
$query->where(function ($query) use ($data, $id) {
$query->where('main_id', $data['main_id'])->whereOr('order_id', $data['main_id']);
});
} else {
$query->where('main_id',$id);
}
$query->where('main_id', $id);
}
return $query->select();
}
@ -2505,46 +2503,94 @@ class StoreOrderRepository extends BaseRepository
$data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
if (!$data) return false;
unset($data[0]);
$mer_cate_id=Db::name('store_category')->where('mer_id',$merId)->where('cate_name','默认分类')->value('store_category_id');
if (!$mer_cate_id ||$mer_cate_id==0){
$mer_cate=['pid'=>0,'cate_name'=>'默认分类','path'=>'/','mer_id'=>$merId,'sort'=>0,'is_show'=>1,'create_time'=>date('Y-m-d H:i:s')];
$mer_cate_id=Db::name('store_category')->insertGetId($mer_cate);
$mer_cate['pid']=$mer_cate_id;
$mer_cate['path']='/'.$mer_cate_id.'/';
$mer_cate['level']=1;
$mer_cate_id=Db::name('store_category')->insertGetId($mer_cate);
$mer_cate_id = Db::name('store_category')->where('mer_id', $merId)->where('cate_name', '默认分类')->value('store_category_id');
if (!$mer_cate_id || $mer_cate_id == 0) {
$mer_cate = ['pid' => 0, 'cate_name' => '默认分类', 'path' => '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
$mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
$mer_cate['pid'] = $mer_cate_id;
$mer_cate['path'] = '/' . $mer_cate_id . '/';
$mer_cate['level'] = 1;
$mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
}
// $type=Db::name('merchant')->where('mer_id',$merId)->value('type_id');
$typeCode=Db::name('merchant_type')->where('mer_type_id',$merId)->value('type_code');
$product_type=0;
// if ($type==12){
if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){
$product_type=98;//供应链
$typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code');
$product_type = 0;
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
$product_type = 98; //供应链
}
foreach ($data as $datum) {
// $find=Db::name('store_product')->where('mer_id', $merId)->where('bar_code', $datum['where']['bar_code'])->find();
// if ($find){
// Db::name('store_product')->where('product_id', $find['product_id'])->update($datum['value']);
// }else{
$store_category_id=Db::name('store_category')->where('mer_id',0)->where('cate_name',$datum['value']['cate_id'])->value('store_category_id');
if ($store_category_id==null){
$store_category_id=438;
$find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find();
$attr_one = explode('|', $datum['value']['attr_one']);
$attr_two = explode('|', $datum['value']['attr_two']);
$arr = [];
if ($find) {
$store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find();
if ($store_product_attr_value) {
Log::error('xls导入商品:已经导入过该规格了');
return false;
}
foreach ($attr_one as $kk => $vv) {
/**查询当前规格是否存在 */
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
->find();
if ($attr_values_find) {
$attr_values= $attr_values_find['attr_values'];
$attr_values = explode('-!-', $attr_values);
if (!in_array($vv, $attr_values)) {
$attr_values[] = $vv;
$attr_values = implode('-!-', $attr_values);
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
}
} else {
$attr_values = $vv;
Db::name('store_product_attr')->insert(
[
'product_id' => $exist['product_id'],
'attr_name' => $kk, 'attr_values' => $attr_values
]
);
}
}
$attrValue['stock'] = 1;
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
$attrValue['unique'] = $unique;
$attrValue['detail'] = json_encode($attrValue['detail']);
$attrValue['product_id'] = $find['product_id'];
$attrValue['mer_id'] = $merId;
Db::name('store_product_attr_value')->insert($attrValue);
} else {
$cate_id = 0;
$spec_type = 0;
$cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id');
if ($cate_id_one) {
$cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id');
if ($cate_id_two) {
$cate_id = $cate_id_two;
}
}
foreach ($attr_one as $k => $v) {
$arr[] = [
'value' => $v,
'detail' => [$attr_two[$k] ?? []],
'inputVisible' => false
];
$spec_type = 1;
}
$datas = [
"image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
"slider_image" => [
0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
],
"store_name" => $datum['value']['store_name'].' '.$datum['value']['specifications'],
"store_name" => $datum['value']['store_name'],
"store_info" => $datum['value']['store_name'],
"keyword" => $datum['value']['keyword'],
"bar_code" => $datum['value']['bar_code'],
"keyword" => '',
"bar_code" => (int) $datum['value']['bar_code'],
"guarantee_template_id" => "",
"cate_id" => $store_category_id,//要修改
"cate_id" => $cate_id,
"mer_cate_id" => [
0 => $mer_cate_id//要修改
0 => $mer_cate_id //要修改
],
'product_type'=>$product_type,
'product_type' => $product_type,
"unit_name" => $datum['value']['unit_name'],
"sort" => 0,
"is_show" => "",
@ -2554,14 +2600,15 @@ class StoreOrderRepository extends BaseRepository
"video_link" => "",
"temp_id" => "",
"content" => "",
"spec_type" => 0,
"spec_type" => $spec_type,
"extension_type" => 0,
"attr" => [],
"attr" => $arr,
"mer_labels" => [],
"delivery_way" => [
0 => "2"
0 => "2",
1 => "1"
],
"delivery_free" => 1,
"delivery_free" => 0,
"param_temp_id" => [],
"extend" => [],
"brand_id" => "",
@ -2572,11 +2619,12 @@ class StoreOrderRepository extends BaseRepository
[
"image" => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
"price" => $datum['value']['price'],
"cost" => $datum['value']['price'],
"cost" => $datum['value']['cost'],
"ot_price" => $datum['value']['price'],
"svip_price" => null,
"stock" => $datum['value']['stock'],
"bar_code" => $datum['value']['bar_code'],
"procure_price" => $datum['value']['procure_price'],
"stock" => 1,
"bar_code" => (int)$datum['value']['bar_code'],
"weight" => 0,
"volume" => 0,
],
@ -2591,11 +2639,15 @@ class StoreOrderRepository extends BaseRepository
"mer_status" => 1,
"rate" => 3,
];
$data_list=[
'data'=>$datas,
'product_type'=>$product_type,
$data_list = [
'data' => $datas,
'product_type' => $product_type,
];
Queue::push(ProductImportJob::class,$data_list);
$make = app()->make(ProductRepository::class);
$id = $make->create($datas, 98);
halt($id);
Queue::push(ProductImportJob::class, $data_list);
}
}
return true;
}
@ -2781,7 +2833,7 @@ class StoreOrderRepository extends BaseRepository
* @param $orderSn
* 更新扫描发货状态
*/
public function deliveryGoods($orderId, $orderSn, $logisticsCode='')
public function deliveryGoods($orderId, $orderSn, $logisticsCode = '')
{
if ($logisticsCode) {
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('logistics_code', $logisticsCode)->where('StoreOrder.status', 1)->where('StoreOrder.is_del', 0)->find();
@ -2792,7 +2844,7 @@ class StoreOrderRepository extends BaseRepository
throw new ValidateException('订单不存在或编码code错误');
if ($order['order_type'])
throw new ValidateException('订单类型错误');
if ($logisticsCode) {
$order->status = 2;
$order->mark = '快递员已完成送货';
@ -2803,5 +2855,4 @@ class StoreOrderRepository extends BaseRepository
}
$order->save();
}
}

View File

@ -224,6 +224,8 @@ class ProductRepository extends BaseRepository
public function create(array $data, int $productType = 0, $conType = 0)
{
if (!$data['spec_type']) {
halt($data['spec_type']);
$data['attr'] = [];
if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误');
}

View File

@ -341,8 +341,8 @@ class MerchantIntention extends BaseController
'name',
'code',
'images',
'merchant_category_name',
'mer_type_id',
'merchant_category_id',
'social_credit_code',
'area_id',
'street_id',
@ -360,14 +360,14 @@ class MerchantIntention extends BaseController
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) {
throw new ValidateException('店铺类型不存在');
}
if ($data['merchant_category_name'] == '') {
throw new ValidateException('商户分类,不能为空');
}
$merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id');
if(!$merchant_category_id){
throw new ValidateException('没有对应的商户分类,请联系工作人员添加');
}
$data['merchant_category_id']=$merchant_category_id;
// if ($data['merchant_category_name'] == '') {
// throw new ValidateException('商户分类,不能为空');
// }
// $merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id');
// if(!$merchant_category_id){
// throw new ValidateException('没有对应的商户分类,请联系工作人员添加');
// }
// $data['merchant_category_id']=$merchant_category_id;
unset($data['code']);
return $data;
}

View File

@ -89,29 +89,10 @@ class StoreImport extends BaseController
$res = $upload->getUploadInfo();
$path = rtrim(public_path(),'/').$res['dir'];
$data = [];
$type_id=Db::name('merchant')->where('mer_id',$this->request->merId())->value('type_id');
switch ($type){
case 'product':
$check =[
'A1'=>'商品名称',
'B1'=>'商品简介',
'C1'=>'关键字',
'D1'=>'商品条码',
'E1'=>'分类',
'F1'=>'单位名',
'G1'=>'出售价',
'H1'=>'总库存',
'I1'=>'规格',
];
SpreadsheetExcelService::instance()->checkImport($path,$check);
$data = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['store_name' => 'A', 'store_info' => 'B', 'keyword' => 'C', 'bar_code' => 'D', 'cate_id' => 'E', 'unit_name' => 'F', 'price' => 'G', 'stock' => 'H', 'specifications' => 'I'],
'where' => ['bar_code' => 'D'],
]
];
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']);
$this->getXlsList($type_id,$path);
return app('json')->success('开始导入数据,请稍后在列表中查看!');
break;
case 'delivery' :
@ -177,5 +158,38 @@ class StoreImport extends BaseController
}
return app('json')->fail('数据类型错误');
}
public function getXlsList($type_id,$path){
if($type_id==12){
$check =[
'A1'=>'商品名称(必填)',
'B1'=>'平台一级类目(必填)',
'C1'=>'平台二级类目(必填)',
'D1'=>'店铺一级商品分类',
'E1'=>'店铺二级商品分类',
'F1'=>'规格组',
'G1'=>'规格值',
'H1'=>'销售单位',
'I1'=>'批发价(必填)',
'J1'=>'零售价(必填)',
'K1'=>'成本价',
'L1'=>'商品条码',
'M1'=>'商品品牌',
];
SpreadsheetExcelService::instance()->checkImport($path,$check);
$data = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['store_name' => 'A', 'cate_id_one' => 'B', 'cate_id_two' => 'C', 'cate_id_one_mer' => 'D', 'cate_id_one_two' => 'E',
'attr_one' => 'F', 'attr_two' => 'G', 'unit_name' => 'H', 'procure_price' => 'I','price'=>'J','cost'=>'K','bar_code'=>'L','brand_id'=>'M'],
'where' => ['bar_code' => 'L'],
]
];
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id']);
}else{
}
}
}

View File

@ -1,120 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
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('数据类型错误');
}
}

View File

@ -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',

View File

@ -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();//取得总行数