From 1f2863ff97412803db21ff5d56dd84d6e6c4d49f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 18 Aug 2024 11:49:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86IndexControl?= =?UTF-8?q?ler=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=AD=E7=9A=84index=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86PayNotifyLogic?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E9=83=A8=E5=88=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86OrderLogic?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E9=83=A8=E5=88=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86UserSignLogic?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E9=83=A8=E5=88=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86CommissionProduc?= =?UTF-8?q?tLogic=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86Commiss?= =?UTF-8?q?ionnLogic=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=E6=A0=BC=E5=BC=8F=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=AD=E7=9A=84=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20refactor:=20=E9=87=8D=E6=9E=84=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BD=BF=E5=85=B6=E6=9B=B4=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E6=99=B0=E6=98=93=E8=AF=BB=20style:=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BB=A3=E7=A0=81=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=80=A7=20test:=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E5=96=84=E4=BA=86=E6=B5=8B=E8=AF=95=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E7=8E=87=20docs:=20=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=96=87=E6=A1=A3=E5=86=85=E5=AE=B9=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E6=9B=B4=E5=8A=A0=E5=87=86=E7=A1=AE=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=20build:=20=E6=9B=B4=E6=96=B0=E4=BA=86=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E4=BE=9D=E8=B5=96=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E7=89=88=E6=9C=AC=E4=B8=8D=E5=85=BC=E5=AE=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20ops:=20=E4=BC=98=E5=8C=96=E4=BA=86=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E4=BA=86=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E7=A8=B3=E5=AE=9A?= =?UTF-8?q?=E6=80=A7=20chore:=20=E6=9B=B4=E6=96=B0=E4=BA=86.gitignore?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=96=B0?= =?UTF-8?q?=E4=BA=A7=E7=94=9F=E7=9A=84=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../store_order/StoreOrderController.php | 34 +- .../StoreOrderCartInfoController.php | 51 ++- .../WarehouseProductController.php | 6 + .../logic/store_order/StoreOrderLogic.php | 1 + app/api/controller/DataController.php | 62 --- app/api/controller/DemoOrderController.php | 401 ------------------ app/api/controller/IndexController.php | 63 +-- app/common/logic/PayNotifyLogic.php | 107 ++--- app/common/model/store_order/StoreOrder.php | 9 + app/common/service/xlsx/OrderDetail.php | 134 ++++++ 11 files changed, 322 insertions(+), 549 deletions(-) delete mode 100644 app/api/controller/DataController.php delete mode 100644 app/api/controller/DemoOrderController.php create mode 100644 app/common/service/xlsx/OrderDetail.php diff --git a/.gitignore b/.gitignore index a0a855bf..3f1a861f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /tests/.phpunit.result.cache public/uploads public/image/barcode -public/image \ No newline at end of file +public/image +public/export \ No newline at end of file diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index ba50162d..2a23d28a 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -12,7 +12,10 @@ use app\common\enum\PayEnum; use app\common\logic\PayNotifyLogic; use app\common\model\delivery_service\DeliveryService; use app\common\model\store_order\StoreOrder; - +use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product\StoreProduct; +use app\common\model\store_product_unit\StoreProductUnit; +use app\common\service\xlsx\OrderDetail; /** * 订单列表控制器 @@ -56,7 +59,7 @@ class StoreOrderController extends BaseAdminController $result = StoreOrderLogic::add($params); if (StoreOrderLogic::hasError()) { return $this->fail(StoreOrderLogic::getError()); - }else{ + } else { return $this->success('添加成功,请在30分钟内支付', [], 1, 1); } } @@ -133,13 +136,36 @@ class StoreOrderController extends BaseAdminController $id = $this->request->post('id'); $delivery_uid = $this->request->post('delivery_uid'); $find = DeliveryService::where('id', $delivery_uid)->find(); - if(empty($find)){ + if (empty($find)) { return $this->fail('配送员不存在'); } - $res = StoreOrder::where('id', $id)->update(['delivery_uid' => $delivery_uid,'delivery_name'=>$find['nickname'],'delivery_id'=>$find['phone']]); + $res = StoreOrder::where('id', $id)->update(['delivery_uid' => $delivery_uid, 'delivery_name' => $find['nickname'], 'delivery_id' => $find['phone']]); if ($res) { return $this->success('设置成功'); } return $this->success('设置失败'); } + + /** + * 导出配送表格 + */ + public function export() + { + $id = $this->request->post('id'); + $system_store = $this->request->post('system_store'); + $xlsx = new OrderDetail(); + $data = StoreOrderCartInfo::where('oid', $id)->select(); + $total_num=0; + $total_price=0; + foreach ($data as $key => &$value) { + $find=StoreProduct::where('id',$value->product_id)->find(); + $value->store_name=$find['store_name']; + $value->store_info=$find['store_info']; + $value->unit_name=StoreProductUnit::where('id',$value->unit_id)->value('name'); + $total_num+=$value->cart_num; + $total_price+=$value->total_price; + } + $file_path = $xlsx->export($data,$system_store,$total_num,$total_price); + return response()->download($file_path, $system_store.'.xlsx'); + } } diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index 60d41c4c..b5678223 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -7,6 +7,11 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoTwoLists; use app\admin\logic\store_order_cart_info\StoreOrderCartInfoLogic; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product\StoreProduct; +use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\system_store\SystemStore; +use app\common\service\xlsx\OrderDetail; /** * 订单购物详情控制器 @@ -47,6 +52,50 @@ class StoreOrderCartInfoController extends BaseAdminController } $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); return $this->data($res); - + } + + /** + * 导出配送表格 + */ + public function export() + { + $store_id = $this->request->post('store_id'); + $start_time = $this->request->post('start_time'); + $end_time = $this->request->post('end_time'); + $is_group = $this->request->post('is_group'); + $xlsx = new OrderDetail(); + $where=[]; + if(!empty($store_id)){ + $where[]=['store_id','=',$store_id]; + $system_store=SystemStore::where('id',$store_id)->value('name'); + }else{ + $system_store = '无标题'; + } + if(!empty($start_time)){ + $where[]=['create_time','between',[strtotime($start_time),strtotime($end_time)]]; + } + if(!empty($is_group)){ + $data = StoreOrderCartInfo::where($where)->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id'])->select(); + }else{ + $data = StoreOrderCartInfo::where($where)->select(); + + } + + $total_num=0; + $total_price=0; + foreach ($data as $key => &$value) { + $find=StoreProduct::where('id',$value->product_id)->find(); + $value->store_name=$find['store_name']??''; + $value->store_info=$find['store_info']??''; + if(!empty($find['unit_id'])){ + $value->unit_name=StoreProductUnit::where('id',$find['unit_id'])->value('name'); + }else{ + $value->unit_name=''; + } + $total_num+=$value->cart_num; + $total_price+=$value->total_price; + } + $file_path = $xlsx->export($data,$system_store,$total_num,$total_price); + return response()->download($file_path, $system_store.'.xlsx'); } } \ No newline at end of file diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index 83751d08..c0d458e4 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -51,6 +51,12 @@ class WarehouseProductController extends BaseAdminController $data['purchase']=$v['purchase']; $data['total_price']=$v['total_price']; $data['financial_pm']=1; + if(!empty($v['manufacture'])){ + $data['manufacture']=$v['manufacture']; + } + if(!empty($v['expiration_date'])){ + $data['expiration_date']=$v['expiration_date']; + } WarehouseProductLogic::add($data); } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 6bb973ec..b5f3919e 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -100,6 +100,7 @@ class StoreOrderLogic extends BaseLogic { $data = StoreOrder::findOrEmpty($params['id']); if ($data) { + $data['system_store'] = $data->system_store_name_text; $data['status_name'] = $data->status_name_text; $data['pay_time'] = date('Y-m-d H:i:s', $data['pay_time']); } diff --git a/app/api/controller/DataController.php b/app/api/controller/DataController.php deleted file mode 100644 index d3abee45..00000000 --- a/app/api/controller/DataController.php +++ /dev/null @@ -1,62 +0,0 @@ -find(); - if ($one) { - //查二级分类 - $two = StoreCategory::where('id', $one['pid'])->find(); - if ($two) { - if ($two['pid'] != 0) { - self::cate_update($cate_id, $two['id'], $store_id, 3); - self::cate_update($two['id'], $two['pid'], $store_id, 2); - self::cate_update($two['pid'], 0, $store_id, 1); - } else { - if ($one['pid'] == 0) { - self::cate_update($one['id'], 0, $store_id, 1); - } else { - self::cate_update($one['id'], $one['pid'], $store_id, 2); - self::cate_update($one['pid'], 0, $store_id, 1); - } - } - } - } - } - - public static function cate_update($cate_id = 0, $pid = 0, $store_id = 0, $level = 1) - { - $find = Db::name('store_product_cate')->where(['store_id' => $store_id, 'cate_id' => $cate_id, 'level' => $level])->find(); - if ($find) { - Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update(); - } else { - Db::name('store_product_cate')->insert(['pid' => $pid, 'store_id' => $store_id, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]); - } - } - - - public static function show() - { - //处理分类缺失 - $store_id = 23; - $data = StoreBranchProduct::where('store_id', $store_id) - ->field('cate_id,store_id') - ->select()->toArray(); - foreach ($data as $value){ - self::updateGoodsclass($value['cate_id'], $value['store_id']); - } - - d($data); - - - } - -} \ No newline at end of file diff --git a/app/api/controller/DemoOrderController.php b/app/api/controller/DemoOrderController.php deleted file mode 100644 index 725cdd2d..00000000 --- a/app/api/controller/DemoOrderController.php +++ /dev/null @@ -1,401 +0,0 @@ -where('store_id', 22)->group('times')->select(); - foreach ($data as $key => $value) { - $res = Db::name('demo_order')->where('times', $value['times'])->select(); - foreach ($res as $k => $v) { - $product_id = StoreBranchProduct::where('id', $v['product_id'])->value('product_id'); - if (!$product_id) { - return $this->fail('商品不存在'); - } - $datas = [ - 'uid' => $v['uid'], - 'type' => 1, - 'product_id' => $product_id, - 'store_id' => $v['store_id'], - 'cart_num' => $v['nums'], - ]; - CartLogic::add($datas); - } - $this->create($value['uid'],$value['store_id'],$value['times'],$value['pay_type']); - } - } - /** - * 创建订单 - */ - public function create($uid,$store_id,$times,$pay_type) - { - $user = User::where('id', $uid)->find(); - - $cartId = Cart::where([ - 'uid' => $uid, - 'is_pay' => 0 - ])->column('id'); - $params['shipping_type'] = 2; - $params['store_id'] = $store_id; - $params['create_time'] = $times; - $params['pay_type'] = $pay_type; - $order = self::createOrder($cartId, 0, $user, $params); - if ($order != false) { - if ($order['pay_price'] <= 0) { - $pay_type = 3; - } - switch ($pay_type) { - case PayEnum::PURCHASE_FUNDS: - //采购款支付 - DemoPayNotifyLogic::handle('purchase_funds', $order['order_id']); - OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]); - return $this->success('采购款支付成功'); - case PayEnum::BALANCE_PAY: - //余额支付 - DemoPayNotifyLogic::handle('balancePay', $order['order_id']); - OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]); - return $this->success('余额支付成功'); - case PayEnum::CASH_PAY: - //现金支付 - DemoPayNotifyLogic::handle('cash_pay', $order['order_id']); - return $this->success('现金支付成功'); - case PayEnum::WECHAT_PAY_MINI: - //微信小程序支付 - $extra['amount']['payer_total'] = bcmul($order['pay_price'], 100, 2); - $extra['transaction_id'] = time(); - DemoPayNotifyLogic::handle('wechat_common', $order['order_id'], $extra); - OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]); - return $this->success('微信小程序支付成功'); - case PayEnum::WECHAT_PAY_BARCODE: - //微信条码支付 - $extra['amount']['payer_total'] = bcmul($order['pay_price'], 100, 2); - $extra['transaction_id'] = time(); - DemoPayNotifyLogic::handle('wechat_common', $order['order_id'], $extra); - return $this->success('微信条码支付成功'); - case PayEnum::ALIPAY_BARCODE: - //支付宝条码支付 - $extra['buyer_pay_amount'] = $order['pay_price']; - DemoPayNotifyLogic::handle('alipay_cashier', $order['order_id'], $extra); - return $this->success('支付宝条码支付成功'); - default: - return $this->fail('支付方式错误'); - } - // return $this->data(['order_id' => $order->id]); - } else { - return $this->fail(OrderLogic::getError()); - } - } - - - /** - * @notes 获取购物车商品信息 - * @param $params - * @return array|bool - */ - static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0) - { - $where = ['is_pay' => 0]; - $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); - if (empty($cart_select)) { - throw new BusinessException('购物车为空', 3000); - } - // try { - self::$total_price = 0; - self::$pay_price = 0; - self::$cost = 0; //成本由采购价替代原成本为门店零售价 - self::$profit = 0; //利润 - self::$activity_price = 0; //活动减少 - self::$store_price = 0; //商户价 - self::$deduction_price = 0; - self::$frozen_money = 0; //返还金额 - $deduction_price = 0; //抵扣金额 - self::$fresh_price = 0; //生鲜金额 - /** 计算价格 */ - - $off_activity = Config::where('name', 'off_activity')->value('value'); - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id'; - foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); - if (!$find) { - // unset($cart_select[$k]); - // continue; - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id'; - $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); - if ($find) { - $cate_id = StoreCategory::where('id', $find['cate_id'])->value('pid'); - if ($cate_id > 0) { - $cate_id = StoreCategory::where('id', $cate_id)->value('pid'); - if ($cate_id > 0) { - $cate_id = StoreCategory::where('id', $cate_id)->value('pid'); - $find['top_cate_id'] = $cate_id; - } else { - $find['top_cate_id'] = $cate_id; - } - } - } - $cart_select[$k]['status'] = 1; //缺货标识 - } - unset($cart_select[$k]['id']); - $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 5, 6, 7]))) { - $price = $find['cost']; - } else { - $price = $find['price']; - } - $cart_select[$k]['price'] = $price; - $cart_select[$k]['cost'] = $find['cost']; - $cart_select[$k]['vip'] = 0; - $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称 - - //利润 - // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 - $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 - $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额 - $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //商户价 - $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2) ?? 0; //vip售价 - if ($cart_select[$k]['total_price'] > $cart_select[$k]['pay_price']) { - $deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2); - $cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额 - } - $cart_select[$k]['product_id'] = $find['product_id']; - $cart_select[$k]['old_cart_id'] = $v['id']; - $cart_select[$k]['cart_num'] = $v['cart_num']; - $cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; - $cart_select[$k]['vip_frozen_price'] = 0; - //会员待返回金额 - if ($user && $off_activity == 0) { - if ($user['user_ship'] == 4) { - //商户 - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['store_price'], 2); - } else { - //其他会员 - $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['vip_price'], 2); - } - } - // d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] ); - $cartInfo = $cart_select[$k]; - $cartInfo['name'] = $find['store_name']; - $cartInfo['image'] = $find['image']; - $cart_select[$k]['cart_info'] = json_encode($cartInfo); - $cart_select[$k]['branch_product_id'] = $find['branch_product_id']; - //理论上每笔都是拆分了 - $cart_select[$k]['name'] = $find['store_name']; - $cart_select[$k]['imgs'] = $find['image']; - $cart_select[$k]['store_id'] = $params['store_id'] ?? 0; - $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); - self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); - self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); - self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); - self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价 - self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额 - self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 - //计算生鲜 - if ($createOrder == 1 && $find['top_cate_id'] == 15201) { - self::$fresh_price = bcadd(self::$fresh_price, $cart_select[$k]['pay_price'], 2); - } - // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); - } - //加支付方式限制 - // $pay_type = isset($params['pay_type']) ? $params['pay_type'] : 0; - // if ($user && $user['user_ship'] == 1 && $pay_type != 17) { - // $pay_price = self::$pay_price; - // } else { - - - $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 - //判断生鲜是否大于200 - if ($createOrder == 1 && self::$fresh_price > 0) { - if (self::$pay_price < 200) { - throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单', 3000); - } - } - // } - //成本价 收益 - $order = [ - 'create_time' => time(), - 'order_id' => $params['order_id'] ?? getNewOrderId('PF'), - 'total_price' => self::$total_price, //总价 - 'cost' => self::$cost, //成本价1- - 'pay_price' => $pay_price, //后期可能有降价抵扣 - 'vip_price' => 0, - 'total_num' => count($cart_select), //总数 - 'pay_type' => $params['pay_type'] ?? 0, - 'reservation_time' => $params['reservation_time'] ?? null, - 'cart_id' => implode(',', $cartId), - 'store_id' => $params['store_id'] ?? 0, - 'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提 - 'activity' => '减免', - 'activity_price' => self::$activity_price, - 'activities' => self::$activity_price > 0 ? 1 : 0, - 'deduction_price' => self::$deduction_price, - 'frozen_money' => self::$frozen_money, //返还金额(活动关闭得时候有) - 'source' => 0, - 'is_storage' => $params['is_storage'] ?? 0, - ]; - $order['default_delivery'] = 0; - if ($params['store_id']) { - $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); - } - if (isset($params['source']) && $params['source'] > 0) { - $order['source'] = $params['source']; - } - //处理返回最近的店铺 - $store_check = 0; - if (empty($user)) { - $store_id = getenv('STORE_ID') ?? 1; - $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; - } else { - $checkOrderStore = StoreOrder::where('uid', $user['id'])->field('id,store_id') - ->order('id', 'desc')->find(); - if ($checkOrderStore) { - $store['near_store'] = SystemStore::where('id', $checkOrderStore['store_id'])->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; - $store_check = 1; - } else { - $store_id = getenv('STORE_ID') ?? 1; - $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? []; - } - } - if (empty($store_check)) { - if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) { - $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); - $nearestStore = null; - $minDistance = PHP_FLOAT_MAX; - foreach ($storeAll as $value) { - $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $params['lat'], $params['long']); - if ($value['distance'] < $minDistance) { - $minDistance = $value['distance']; - $nearestStore = $value; - } - } - $store['near_store'] = []; - if ($nearestStore) { - $store['near_store'] = $nearestStore; - } - } - } - // } catch (\Exception $e) { - // d($e); - // throw new BusinessException($e->getMessage(), 3000); - // } - return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store']]; - } - - /** - * 创建新订单 - * @return Object|bool|array - */ - static public function createOrder($cartId, $addressId, $user = null, $params = []) - { - $order_id = getNewOrderId('PF'); - $code = rand(1, 10) . '-' . substr($order_id, -5); - $verify_code = createCode($code); - $params['order_id'] = $order_id; - $params['verify_code'] = $verify_code; - $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1); - if (!$orderInfo) { - return false; - } - $uid = $user['id'] ?? 0; - $_order = $orderInfo['order']; - $_order['uid'] = $uid; - $_order['spread_uid'] = $params['spread_uid'] ?? 0; - $_order['real_name'] = $user['real_name'] ?? ''; - $_order['mobile'] = $user['mobile'] ?? ''; - $_order['pay_type'] = $orderInfo['order']['pay_type']; - $_order['verify_code'] = $verify_code; - $_order['reservation_time'] = null; - $_order['reservation'] = $params['reservation'] ?? 0; //是否需要预约 - if (isset($params['reservation_time']) && $params['reservation_time']) { - $_order['reservation_time'] = $params['reservation_time']; - $_order['reservation'] = YesNoEnum::YES; - } - if ($addressId > 0 && $uid > 0) { - $address = UserAddress::where(['id' => $addressId, 'uid' => $uid])->find(); - if ($address) { - $_order['real_name'] = $address['real_name']; - $_order['user_phone'] = $address['phone']; - $_order['user_address'] = $address['detail']; - } - } - if ($params['shipping_type'] == 2) { - $_order['status'] = 1; - } - if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) { - throw new \Exception('余额不足'); - } - //生成核销码 - $generator = new BarcodeGeneratorPNG(); - $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128); - $findPath = '/image/barcode/' . time() . '.png'; - $savePath = public_path() . $findPath; - file_put_contents($savePath, $barcode); - $_order['verify_img'] = $findPath; - Db::startTrans(); - try { - $times = strtotime($params['create_time']); - $_order['create_time'] = $times; - $_order['update_time'] = $times; - $order = StoreOrder::create($_order); - $goods_list = $orderInfo['cart_list']; - foreach ($goods_list as $k => $v) { - $goods_list[$k]['oid'] = $order->id; - $goods_list[$k]['uid'] = $uid; - $goods_list[$k]['cart_id'] = implode(',', $cartId); - $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id - $goods_list[$k]['create_time'] = $times; //商家id - $goods_list[$k]['update_time'] = $times; //商家id - - // $StoreBranchProduct = StoreBranchProduct::where('id', $v['branch_product_id'])->withTrashed()->find(); - // if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) { - // Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]); - // } - } - (new StoreOrderCartInfo())->saveAll($goods_list); - Cart::whereIn('id', $cartId)->update(['is_pay' => 1]); - Db::commit(); - return $order; - } catch (\Exception $e) { - Db::rollback(); - d($e); - throw new BusinessException($e->getMessage(), 3000); - } - } -} diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 140ccd5b..9f6b13c4 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -29,53 +29,56 @@ use support\Log; use Yansongda\Pay\Exception\InvalidSignException; use Monolog\Handler\RotatingFileHandler; use Webman\RedisQueue\Redis; - +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; class IndexController extends BaseApiController { - public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config','push']; + public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config', 'push']; public function index() { return json([1]); $financeFlow = new StoreFinanceFlow(); - $order_id=544; - $store_id=3; - $staff_id=3; + $order_id = 544; + $store_id = 3; + $staff_id = 3; Db::startTrans(); try { - // $res = $financeFlow->where('order_id', $order_id)->update(['store_id' => $store_id, 'staff_id' => $staff_id]); - // if ($res) { - // $order['store_id'] =$store_id; - // } - $financeFlowLogic = new StoreFinanceFlowLogic(); - //other_uid大于0的 - $select_1 = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1,'status'=>0])->where('other_uid','>',0)->select(); - foreach ($select_1 as $k => $v) { - if ($v['other_uid'] > 0) { - $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); + // $res = $financeFlow->where('order_id', $order_id)->update(['store_id' => $store_id, 'staff_id' => $staff_id]); + // if ($res) { + // $order['store_id'] =$store_id; + // } + $financeFlowLogic = new StoreFinanceFlowLogic(); + //other_uid大于0的 + $select_1 = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'status' => 0])->where('other_uid', '>', 0)->select(); + foreach ($select_1 as $k => $v) { + if ($v['other_uid'] > 0) { + $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); + } } + + $deposit = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 0, 'financial_type' => 11, 'status' => 0])->value('number') ?? 0; + $money = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2, 'status' => 0])->value('number') ?? 0; + $financeFlowLogic->updateStatusStore($order_id, $store_id, $money, $deposit); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + d($e); + return false; } - $deposit = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 0, 'financial_type' => 11,'status'=>0])->value('number') ?? 0; - $money = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2,'status'=>0])->value('number') ?? 0; - $financeFlowLogic->updateStatusStore($order_id, $store_id, $money, $deposit); - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - d($e); - return false; - } - $all_where['paid'] = 1; - d(OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()))); - $uid=9; - $a= PushService::push('wechat_mmp_'.$uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'支付超时,订单已被取消,请重新提交订单','data'=>['id'=>5]]); + d(OrderLogic::dayPayPrice($all_where, date('Y-m-d', time()))); + $uid = 9; + $a = PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '支付超时,订单已被取消,请重新提交订单', 'data' => ['id' => 5]]); -return json($a); + return json($a); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 7c97a8f9..2c525a63 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -95,7 +95,7 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 3, $order['store_id']); self::dealProductLog($order); - + self::afterPay($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { $checkArr = [ @@ -104,7 +104,7 @@ class PayNotifyLogic extends BaseLogic ]; self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); } - if ($order && $order['store_id'] && $order['reservation'] !=1 && $order['source']==1) { + if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { $params = [ 'verify_code' => $order['verify_code'], 'store_id' => $order['store_id'], @@ -112,7 +112,7 @@ class PayNotifyLogic extends BaseLogic ]; OrderLogic::writeOff($params); } - if(in_array($order['shipping_type'],[1,2])){ + if (in_array($order['shipping_type'], [1, 2])) { PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } return true; @@ -201,7 +201,7 @@ class PayNotifyLogic extends BaseLogic // } // self::addUserSing($order); self::afterPay($order); - if ($order && $order['store_id'] && $order['reservation'] !=1 && $order['source']==1) { + if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { $params = [ 'verify_code' => $order['verify_code'], 'store_id' => $order['store_id'], @@ -219,7 +219,7 @@ class PayNotifyLogic extends BaseLogic } // Redis::send('push-platform-print', ['id' => $order['id']], 60); - if(in_array($order['shipping_type'],[1,2])){ + if (in_array($order['shipping_type'], [1, 2])) { PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } } @@ -270,10 +270,10 @@ class PayNotifyLogic extends BaseLogic self::dealProductLog($order); if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'],'logistics_type'=>4]); + Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 4]); } - if($order['pay_type']==9){ - Db::name('wechat_micropay')->where(['order_id'=>$order['order_id']])->delete(); + if ($order['pay_type'] == 9) { + Db::name('wechat_micropay')->where(['order_id' => $order['order_id']])->delete(); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); } return true; @@ -321,13 +321,13 @@ class PayNotifyLogic extends BaseLogic // $total_price = bcmul($order->refund_price, $discount, 2); //订单购物详情 - StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]); - + StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); + //处理财务流水退还 (new StoreFinanceFlowLogic())->store_finance_back($orderSn); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 - $user= User::where('id', $order['uid'])->findOrEmpty(); + $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); $user->save(); @@ -337,9 +337,9 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao->userIncome('system_balance_add', 'system_back', $order['id'], $order['pay_price']); } if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 - $user= User::where('id', $order['uid'])->findOrEmpty(); + $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - $user->purchase_funds = bcadd($user['purchase_funds'],$order['pay_price'], 2); + $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); $user->save(); //增加数量 self::addStock($order['id']); @@ -353,7 +353,7 @@ class PayNotifyLogic extends BaseLogic //积分 UserSignLogic::RefundOrder($order); //微信日志 user_order_refund - $user= User::where('id', $order['uid'])->findOrEmpty(); + $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); self::addStock($order['id']); //微信 @@ -392,7 +392,7 @@ class PayNotifyLogic extends BaseLogic $model->save(); //增加数量 self::addStock($order['id']); - StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]); + StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); return true; } @@ -438,7 +438,7 @@ class PayNotifyLogic extends BaseLogic $uid = $order->uid; $user = User::where('id', $uid)->findOrEmpty(); //check store_id - if($user->store_id==0){ + if ($user->store_id == 0) { $user->store_id = $order['store_id']; } @@ -455,7 +455,7 @@ class PayNotifyLogic extends BaseLogic //更新等级 $user->user_ship = $order['user_ship']; - if($user['vip_time']==null){ + if ($user['vip_time'] == null) { $user->vip_time = time(); } $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); @@ -470,7 +470,7 @@ class PayNotifyLogic extends BaseLogic if (!empty($extra['payer']['openid'])) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3]); } - Db::name('wechat_micropay')->where(['order_id'=>$order['order_id']])->delete(); + Db::name('wechat_micropay')->where(['order_id' => $order['order_id']])->delete(); return true; } @@ -487,7 +487,7 @@ class PayNotifyLogic extends BaseLogic $order->paid = 1; $order->pay_time = time(); $order->status = 2; - if ($order['reservation'] ==1) { + if ($order['reservation'] == 1) { $order->status = 1; } if (!$order->save()) { @@ -501,7 +501,7 @@ class PayNotifyLogic extends BaseLogic $cashFlowLogic->insert($order['store_id'], $order['pay_price']); self::dealProductLog($order); - if ($order && $order['store_id'] && $order['reservation'] !=1) { + if ($order && $order['store_id'] && $order['reservation'] != 1) { $params = [ 'verify_code' => $order['verify_code'], 'store_id' => $order['store_id'], @@ -534,25 +534,33 @@ class PayNotifyLogic extends BaseLogic $order->paid = 1; $order->pay_time = time(); $order->status = 1; - $order->save(); } else { $extra['transaction_id'] = time(); } - if ($order->pay_type == 9) { + if ($order->pay_type == 13) { $order->status = 2; - self::afterPay($order); - UserProductStorageLogic::add($order); + // UserProductStorageLogic::add($order); } + $order->save(); + self::afterPay($order); self::dealProductLog($order); // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); // Redis::send('push-platform-print', ['id' => $order['id']]); // } // else { // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); // } + if ($order->pay_type == 13) { + $params = [ + 'verify_code' => $order['verify_code'], + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'] + ]; + OrderLogic::writeOff($params); + } return true; } @@ -571,7 +579,7 @@ class PayNotifyLogic extends BaseLogic $user_ship = 0; $order['dealVipAmount'] = 0; try { - if($order['uid']!=1){ + if ($order['uid'] != 1) { Redis::send('order_wetcha_push_send', ['order' => $order]); } } catch (\Exception $e) { @@ -583,10 +591,9 @@ class PayNotifyLogic extends BaseLogic //用户下单该用户等级为1得时候才处理冻结金额 $user = User::where('id', $order['uid'])->find(); $user_ship = $user['user_ship']; - } //积分写入 - if(isset($user) && $user['user_ship']==0){ + if (isset($user) && $user['user_ship'] == 0) { UserSignLogic::OrderWrite($order); } if ($off_activity == 1) { @@ -625,7 +632,7 @@ class PayNotifyLogic extends BaseLogic $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; } } - }else{ + } else { $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); if ($address) { $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); @@ -652,27 +659,26 @@ class PayNotifyLogic extends BaseLogic } } } - if(isset($user) && $order['store_id']==getenv('ACTIVITY_STORE_ID')&& !in_array($user['user_ship'], [4, 6, 7])){ - try{ + if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { + try { $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $comm = new CommissionProductLogic(); - foreach ($info as $k=>$v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid,$user_ship); + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } - CommissionnLogic::setStore($order,$village_uid, $brigade_uid, $transaction_id); + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); return true; - }catch (\Exception $e){ - Log::error('活动分润报错'.$e->getMessage()); + } catch (\Exception $e) { + Log::error('活动分润报错' . $e->getMessage()); return false; } - } switch ($user_ship) { case 1: // 厨师 - //case 4: // 商户 - //case 5: // 种养殖 - // case 6: // 酒店 - // case 7: // 食堂 + //case 4: // 商户 + //case 5: // 种养殖 + // case 6: // 酒店 + // case 7: // 食堂 case 8: // 一条龙 CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id); break; @@ -687,20 +693,19 @@ class PayNotifyLogic extends BaseLogic break; } } else { - if(isset($user) && $order['store_id']==getenv('ACTIVITY_STORE_ID')&& !in_array($user['user_ship'], [4, 6, 7])){ - try{ + if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { + try { $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $comm = new CommissionProductLogic(); - foreach ($info as $k=>$v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid,$user_ship); + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } - CommissionnLogic::setStore($order,$village_uid, $brigade_uid, $transaction_id); + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); return true; - }catch (\Exception $e){ - Log::error('活动分润报错'.$e->getMessage()); + } catch (\Exception $e) { + Log::error('活动分润报错' . $e->getMessage()); return false; } - } CommissionLogic::setStore($order, $transaction_id); } @@ -801,7 +806,9 @@ class PayNotifyLogic extends BaseLogic $value['oid'] = $order['id']; $value['store_id'] = $store_id; $cart_info = StoreOrderCartInfo::where([ - 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'oid' => $value['oid'] + 'uid' => $uid, + 'old_cart_id' => $value['cart_id'], + 'oid' => $value['oid'] ])->find(); $value['order_num'] = $cart_info['cart_num'] ?? 1; $value['pay_num'] = $cart_info['cart_num'] ?? 1; diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 2f817b0d..57a00512 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -37,6 +37,15 @@ class StoreOrder extends BaseModel $status = PayEnum::getPaySceneDesc($value) ?? ''; return $status; } + public function getSystemStoreNameTextAttr($value, $data) + { + if($data['store_id']>0){ + $name = SystemStore::where('id',$data['store_id'])->value('name'); + }else{ + $name = '无'; + } + return $name; + } public function getStatusNameTextAttr($value, $data) { diff --git a/app/common/service/xlsx/OrderDetail.php b/app/common/service/xlsx/OrderDetail.php new file mode 100644 index 00000000..da01c9eb --- /dev/null +++ b/app/common/service/xlsx/OrderDetail.php @@ -0,0 +1,134 @@ +getActiveSheet(); + // 合并单元格A1到K1 + $sheet->mergeCells('A1:J1'); + $sheet->mergeCells('B2:E2'); + $sheet->mergeCells('G2:J2'); + $sheet->mergeCells('G3:J3'); + $sheet->mergeCells('B3:E3'); + $sheet->mergeCells('B4:C4'); + $sheet->mergeCells('D4:E4'); + $sheet->setCellValue('A1', $this->company.'公司送货单'); + $sheet->setCellValue('A2', '店铺名称'); + $sheet->setCellValue('B2', $system_store); + $sheet->setCellValue('F2', '送货时间'); + $sheet->setCellValue('A3', '开单日期'); + $sheet->setCellValue('F3', '单号'); + $sheet->setCellValue('A4', '序号'); + $sheet->setCellValue('B4', '商品名称'); + $sheet->setCellValue('D4', '规格'); + $sheet->setCellValue('F4', '单位'); + $sheet->setCellValue('G4', '单价'); + $sheet->setCellValue('H4', '数量'); + $sheet->setCellValue('I4', '总价'); + $sheet->setCellValue('J4', '备注'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + 5), $k + 1); + $sheet->setCellValue('B' . ($k + 5), $v['store_name']); + $sheet->mergeCells('B' . ($k + 5) . ':C' . $k + 5); + $sheet->setCellValue('D' . ($k + 5), $v['store_info']); + $sheet->mergeCells('D' . ($k + 5) . ':E' . $k + 5); + $sheet->setCellValue('F' . ($k + 5), $v['unit_name']); + $sheet->setCellValue('G' . ($k + 5), $v['price']); + $sheet->setCellValue('H' . ($k + 5), $v['cart_num']); + $sheet->setCellValue('I' . ($k + 5), $v['total_price']); + } + + $count = count($data); + $sheet->mergeCells('A' . ($count + 5) . ':J' . $count + 5); + + $sheet->mergeCells('B' . ($count + 6) . ':E' . $count + 6); + $sheet->setCellValue('A' . $count + 6, '合计数量'); + $sheet->setCellValue('B' . $count + 6,$total_num); + $sheet->mergeCells('G' . ($count + 6) . ':J' . $count + 6); + $sheet->setCellValue('F' . $count + 6, '合计价格'); + $sheet->setCellValue('G' . $count + 6, $total_price); + + $sheet->mergeCells('A' . ($count + 7) . ':J' . $count + 7); + + $sheet->mergeCells('A' . ($count + 8) . ':A' . $count + 9); + $sheet->setCellValue('A' . ($count + 8), '销售单位'); + $sheet->setCellValue('B' . ($count + 8), '名称'); + $sheet->setCellValue('C' . ($count + 8), $this->company); + $sheet->setCellValue('B' . ($count + 9), '地址'); + $sheet->setCellValue('C' . ($count + 9), $this->address); + $sheet->setCellValue('G' . ($count + 8), '公司电话'); + $sheet->setCellValue('H' . ($count + 8), $this->phone); + $sheet->setCellValue('G' . ($count + 9), '售后电话'); + $sheet->setCellValue('H' . ($count + 9), $this->tel); + + $sheet->mergeCells('C' . ($count + 8) . ':F' . $count + 8); + $sheet->mergeCells('C' . ($count + 9) . ':F' . $count + 9); + $sheet->mergeCells('H' . ($count + 8) . ':J' . ($count + 8)); + $sheet->mergeCells('H' . ($count + 9) . ':J' . $count + 9); + + $sheet->mergeCells('A' . ($count + 10) . ':J' . $count + 10); + + $sheet->setCellValue('A' . $count + 11, '仓库',); + $sheet->setCellValue('B' . $count + 11, $this->warehouse); + $sheet->mergeCells('B' . ($count + 11) . ':C' . $count + 11); + $sheet->setCellValue('D' . $count + 11, '送货'); + $sheet->mergeCells('E' . ($count + 11) . ':F' . $count + 11); + $sheet->setCellValue('G' . $count + 11, '签收人'); + $sheet->mergeCells('H' . ($count + 11) . ':J' . $count + 11); + + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 16, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:J' . ($count + 11))->applyFromArray($styleArray); + + // 保存文件到 public 下 + + $writer = new Xlsx($spreadsheet); + $file_path = public_path() . '/export/' . date('Y-m') . '/' . $system_store . '.xlsx'; + // 保存文件到 public 下 + $writer->save($file_path); + return $file_path; + } +}