diff --git a/app/admin/controller/purchase_order/PurchaseOrderController.php b/app/admin/controller/purchase_order/PurchaseOrderController.php index 390727d2..9fec61fc 100644 --- a/app/admin/controller/purchase_order/PurchaseOrderController.php +++ b/app/admin/controller/purchase_order/PurchaseOrderController.php @@ -1,11 +1,16 @@ -dataLists(new PurchaseOrderInfoLists()); } + public function order_lists() + { + $id = $this->request->get('id'); + $order_arr = PurchaseOrder::where('id', $id)->value('order_arr'); + $this->request->__set('order_arr', $order_arr); + return $this->dataLists(new StoreOrderLists); + } /** * 合并今日商户订单 */ - public function add(){ - PurchaseOrderLogic::StoreTodayOrder(); + public function add() + { + $data = $this->request->post(); + PurchaseOrderLogic::mergeOrder($data); + if (PurchaseOrderLogic::hasError()) { + return $this->fail(PurchaseOrderLogic::getError()); + } return $this->success('合并成功'); } - /** + /** * 合并今日平台订单 */ - public function platform(){ + public function platform() + { PurchaseOrderLogic::platformTodayOrder(); return $this->success('合并成功'); } - /** + /** * 详情 */ - public function detail(){ - $id=$this->request->get('id'); - $res=PurchaseOrderLogic::detail($id); + public function detail() + { + $id = $this->request->get('id'); + $res = PurchaseOrderLogic::detail($id); return $this->data($res); - } -} \ No newline at end of file + } +} diff --git a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php index f4005891..565a3c41 100644 --- a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -28,7 +28,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc public function setSearch(): array { return [ - '=' => [], + '=' => ['order_id'], ]; } @@ -51,6 +51,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc ->select()->each(function($item){ $find=StoreProduct::where('id',$item->product_id)->find(); $item->store_name=$find->store_name; + $item->store_info=$find->store_info; $item->image=$find->image; $item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); if($item->is_buyer==1){ diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 6e4f589d..257f776a 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -30,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'], + '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge'], 'between_time' => 'create_time' ]; } @@ -50,6 +50,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface if($this->request->get('is_delivery')>=1){ $this->searchWhere[]=['delivery_uid','>',0]; } + if($this->request->__get('order_arr')){ + $this->searchWhere[]=['id','in',$this->request->__get('order_arr')]; + } return StoreOrder::with(['staff','store'])->where($this->searchWhere) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->request->adminInfo['store_id']); @@ -62,7 +65,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $query->whereIn('status', $status); } }) - ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id']) + ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/app/admin/logic/purchase_order/PurchaseOrderLogic.php b/app/admin/logic/purchase_order/PurchaseOrderLogic.php index cab70096..83f97290 100644 --- a/app/admin/logic/purchase_order/PurchaseOrderLogic.php +++ b/app/admin/logic/purchase_order/PurchaseOrderLogic.php @@ -6,8 +6,10 @@ namespace app\admin\logic\purchase_order; use app\common\model\purchase_order\PurchaseOrder; use app\common\logic\BaseLogic; use app\common\model\purchase_order_info\PurchaseOrderInfo; +use app\common\model\purchase_product_offer\PurchaseProductOffer; 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\system_store\SystemStore; use think\facade\Db; @@ -20,6 +22,54 @@ use think\facade\Db; class PurchaseOrderLogic extends BaseLogic { + public static function mergeOrder($params) + { + $oid_arr = []; + $store_arr = []; + foreach ($params as $k => $v) { + $oid_arr[] = $v['oid']; + $store_arr[] = $v['store_id']; + } + $store_arr = array_unique($store_arr); + Db::startTrans(); + try { + $price = StoreOrder::whereIn('id', $oid_arr)->field('SUM(pay_price) as pay_price,SUM(total_price) as total_price')->find(); + $data = [ + 'store_id' => 0, + 'store_arr' => json_encode($store_arr), + 'order_arr' => json_encode($oid_arr), + 'order_id' => getNewOrderId('PT'), + 'total' => $price['total_price'], + 'actual' => $price['pay_price'], + 'money' => $price['pay_price'], + 'paid' => 1, + 'is_mer' => 2, + 'create_time' => time(), + 'update_time' => time(), + ]; + $res = PurchaseOrder::create($data); + $info = StoreOrderCartInfo::where('oid', 'in', $oid_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('product_id')->select(); + $purchase_order_info = []; + foreach ($info as $item) { + $arr['order_id'] = $res['id']; + $arr['product_id'] = $item['product_id']; + $arr['price'] = $item['price']; + $arr['total_price'] = $item['total_price']; + $arr['need_num'] = $item['cart_num']; + $arr['unit'] = StoreProduct::where('id',$item['product_id'])->value('unit'); + $purchase_order_info[] = $arr; + } + $purchaseOrderInfo = new PurchaseProductOffer(); + $purchaseOrderInfo->saveAll($purchase_order_info); + StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** * @notes 合并今日商户订单 @@ -85,8 +135,8 @@ class PurchaseOrderLogic extends BaseLogic Db::startTrans(); try { $purchaseOrderInfo = new PurchaseOrderInfo(); - $purchase_order_info=[]; - $order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer',1)->column('id'); + $purchase_order_info = []; + $order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer', 1)->column('id'); $price = PurchaseOrder::whereDay('create_time')->field('SUM(actual) as pay_price,SUM(total) as total_price')->find(); $data = [ 'store_id' => 0, @@ -118,7 +168,6 @@ class PurchaseOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - d($e); self::setError($e->getMessage()); return false; } @@ -146,12 +195,12 @@ class PurchaseOrderLogic extends BaseLogic */ public static function detail($id): array { - $data= PurchaseOrder::findOrEmpty($id)->toArray(); - if($data){ - if($data['store_id']){ - $data['system_store']=SystemStore::where('id',$data['store_id'])->value('name'); - }else{ - $data['system_store']='平台'; + $data = PurchaseOrder::findOrEmpty($id)->toArray(); + if ($data) { + if ($data['store_id']) { + $data['system_store'] = SystemStore::where('id', $data['store_id'])->value('name'); + } else { + $data['system_store'] = '平台'; } switch ($data['storage']) { case 0: diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index f9d82253..389a01ec 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -294,7 +294,7 @@ class UserController extends BaseApiController public function cash_info() { $info = User::where('id', $this->userId)->field('id,real_name,mobile,now_money,id_card')->find(); - $info['notes'] = '提现金额需大于1元,提现到微信零钱,并财务审核,审核通过后,提现金额将自动到账'; + $info['notes'] = '提现金额需大于1元,提现到微信零钱,并财务审核,审核通过后,提现金额将自动到账。若本月提现超过800元,将产生个人所得税款,具体税率及金额根据《中华人民共和国个人所得税法》第二条、第三条、第六条规定扣缴。'; $info['extract_price'] =StoreExtract::where('uid',$this->userId)->sum('extract_price'); return $this->data($info); } diff --git a/app/common/model/purchase_order/PurchaseOrder.php b/app/common/model/purchase_order/PurchaseOrder.php index f05cb308..b0bb36cb 100644 --- a/app/common/model/purchase_order/PurchaseOrder.php +++ b/app/common/model/purchase_order/PurchaseOrder.php @@ -17,6 +17,6 @@ class PurchaseOrder extends BaseModel use SoftDelete; protected $name = 'purchase_order'; protected $deleteTime = 'delete_time'; - protected $json = ['order_arr']; + protected $json = ['order_arr','store_arr']; } \ No newline at end of file