diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 14026a8b2..d739c8436 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -339,4 +339,17 @@ class WorkbenchController extends BaseAdminController return $this->data([], '操作失败', 400); } } + /** + * 更新库存和价值 + */ + public function stock_product_price() + { + $parmas = $this->request->get(); + $res = WarehouseLogic::stockProductPrice($parmas); + if($res){ + return $this->success('操作成功,请刷新页面',[],1,1); + }else{ + return $this->fail('操作失败'); + } + } } diff --git a/app/admin/controller/store_branch_product/StoreBranchProductController.php b/app/admin/controller/store_branch_product/StoreBranchProductController.php index 2d3b59dd5..efd9f862e 100644 --- a/app/admin/controller/store_branch_product/StoreBranchProductController.php +++ b/app/admin/controller/store_branch_product/StoreBranchProductController.php @@ -46,18 +46,13 @@ class StoreBranchProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('add'); $result = StoreProductLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(StoreProductLogic::getError()); + return $this->success('添加成功', [], 1, 1); + } public function update() { $params = $this->request->post(); StoreBranchProductLogic::edit($params); - if (StoreBranchProductLogic::hasError()) { - return $this->fail(StoreBranchProductLogic::getError()); - } return $this->success('更新成功', [], 1, 1); } @@ -110,9 +105,6 @@ class StoreBranchProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('delete'); StoreBranchProductLogic::delete($params); - if(StoreBranchProductLogic::hasError()){ - return $this->fail(StoreBranchProductLogic::getError()); - } return $this->success('删除成功', [], 1, 1); } diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 092c9bb9a..efa371bbe 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -7,15 +7,22 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\store_order\StoreOrderLists; use app\admin\lists\store_order\StoreRefundOrderLists; use app\admin\logic\store_order\StoreOrderLogic; +use app\admin\logic\store_product\StoreProductLogic; +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\validate\store_order\StoreOrderValidate; use app\common\enum\PayEnum; use app\common\logic\PayNotifyLogic; use app\common\model\delivery_service\DeliveryService; +use app\common\model\store_branch_product\StoreBranchProduct; 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\model\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; use app\common\service\xlsx\OrderDetail; +use support\exception\BusinessException; +use think\facade\Db; /** * 订单列表控制器 @@ -117,7 +124,7 @@ class StoreOrderController extends BaseAdminController */ public function refund() { - $params = (new StoreOrderValidate())->goCheck('refund'); + $params = $this->request->post(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty(); if (empty($detail)) { return $this->fail('无该订单请检查'); @@ -155,23 +162,94 @@ class StoreOrderController extends BaseAdminController $id = $this->request->post('id'); $system_store = $this->request->post('system_store'); $xlsx = new OrderDetail(); - $order=StoreOrder::where('id',$id)->findOrEmpty(); - $time= strtotime('+1 day', $order['pay_time']); - $order['pay_time']=date('Y-m-d H:i:s',$order['pay_time']); - $order['delivery_time']=date('Y-m-d', $time); + $order = StoreOrder::where('id', $id)->findOrEmpty(); + $time = strtotime('+1 day', $order['pay_time']); + $order['pay_time'] = date('Y-m-d H:i:s', $order['pay_time']); + $order['delivery_time'] = date('Y-m-d', $time); $data = StoreOrderCartInfo::where('oid', $id)->select(); 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'])){ - $value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name'); + if(in_array($order['store_id'],[17,18])){ + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); }else{ - $value->unit_name=''; + $find = StoreProduct::where('id', $value->product_id)->find(); + } + $value->store_name = $find['store_name'] ?? ''; + $value->store_info = $find['store_info'] ?? ''; + $value->total_price = bcmul($value['price'], $value['cart_num'], 2); + if (!empty($find['unit'])) { + $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + } else { + $value->unit_name = ''; } } - $file_path = $xlsx->export($data,$system_store,$order); + $order['total_price'] = $order['pay_price']; + $file_path = $xlsx->export($data, $system_store, $order); return $this->success('导出成功', ['url' => $file_path]); } + + /** + * 创建出库单 + */ + public function createOutboundOrder() + { + $id = $this->request->post('id'); + $store_id = $this->request->post('store_id'); + $warehouse_id = $this->request->post('warehouse_id'); + $delivery_time = $this->request->post('delivery_time'); + $mark = $this->request->post('mark'); + $find = WarehouseOrder::where('oid',$id)->find(); + if($find){ + return $this->fail('该订单已创建出库单'); + } + $product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select(); + if(!$product_arr){ + return $this->fail('无商品'); + } + Db::startTrans(); + try { + $arr = [ + 'oid' => $id, + 'warehouse_id' => $warehouse_id, + 'store_id' => $store_id, + 'supplier_id' => 0, + 'code' => getNewOrderId('PS'), + 'admin_id' => $this->adminId, + 'financial_pm' => 0, + 'batch' => 0, + 'mark' => $mark ?? "", + ]; + $arr['delivery_time'] = strtotime($delivery_time); + $res = WarehouseOrder::create($arr); + foreach ($product_arr as $key => $arr) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['stock'], + 'status' => 1, + 'admin_id' => $this->adminId, + ]; + $storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + if ($arr['stock'] == 0) { + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct); + } else { + $data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2); + $data['purchase'] = $storeProduct['purchase']; + $data['oid'] = $res['id']; + $data['financial_pm'] = 0; + WarehouseProductLogic::add($data); + $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); + } + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); + } } diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index a6aabe21a..955f37fa5 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -54,7 +54,37 @@ class StoreOrderCartInfoController extends BaseAdminController $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); return $this->data($res); } + /** + * @notes 追加订单商品 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function add() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::add($params); + return $this->success('添加成功', [], 1, 1); + } + /** + * @notes 编辑订单商品 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function edit() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::edit($params); + return $this->success('编辑成功', [], 1, 1); + } + public function del() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::del($params); + return $this->success('删除成功', [], 1, 1); + } /** * 导出配送表格 */ diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 3a5d34ea7..1e7fe44e3 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -44,9 +44,7 @@ class StoreProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('add'); $result = StoreProductLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } + return $this->success('添加成功', [], 1, 1); } @@ -62,12 +60,20 @@ class StoreProductController extends BaseAdminController d($params); $result = StoreProductLogic::edit($params); - if (true === $result) { - return $this->success('编辑成功', [], 1, 1); - } - return $this->fail(StoreProductLogic::getError()); + return $this->success('编辑成功', [], 1, 1); + } + /** + * @notes 修改商品状态 + * @return \think\response\Json + * @date 2024/05/31 10:53 + */ + public function status(){ + $params=$this->request->post(); + StoreProduct::where('id',$params['id'])->update(['is_show'=>$params['is_show']]); + return $this->success('操作成功',[],1,1); + } /** * @notes 删除商品列表 diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php index e327dc7ec..748652db1 100644 --- a/app/admin/controller/system_store/SystemStoreController.php +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -40,35 +40,6 @@ class SystemStoreController extends BaseAdminController { return $this->dataLists(new SystemStoreSourceLists()); } - /** - * @notes 根据商品源获取门店列表 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 17:45 - */ - public function source_product_update_store() - { - $addList=$this->request->post('addList'); - $product_id=$this->request->post('product_id'); - if($addList){ - foreach ($addList as $key=>$value){ - StoreProductLogic::copy($product_id,$value); - if(StoreProductLogic::hasError()){ - return $this->fail(StoreProductLogic::getError()); - } - } - } - $removeList=$this->request->post('removeList'); - if($removeList){ - foreach ($removeList as $key=>$value){ - StoreProductLogic::store_del($product_id,$value); - if(StoreProductLogic::hasError()){ - return $this->fail(StoreProductLogic::getError()); - } - } - } - return $this->success('设置成功', [], 1, 1); - } /** * @notes 添加门店列表 diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 5c2876fb4..787347de1 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -58,7 +58,6 @@ class WarehouseOrderController extends BaseAdminController if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(WarehouseOrderLogic::getError()); } /** * @notes 添加出库单 @@ -125,7 +124,6 @@ class WarehouseOrderController extends BaseAdminController Db::commit(); } catch (\Throwable $e) { Db::rollback(); - d($e); throw new BusinessException($e->getMessage()); } return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); @@ -146,7 +144,6 @@ class WarehouseOrderController extends BaseAdminController if (true === $result) { return $this->success('编辑成功', [], 1, 1); } - return $this->fail(WarehouseOrderLogic::getError()); } /** @@ -174,9 +171,6 @@ class WarehouseOrderController extends BaseAdminController { $params = (new WarehouseOrderValidate())->post()->goCheck('delete'); WarehouseOrderLogic::delete($params); - if(WarehouseOrderLogic::hasError()){ - return $this->fail(WarehouseOrderLogic::getError()); - } return $this->success('删除成功', [], 1, 1); } @@ -233,7 +227,11 @@ class WarehouseOrderController extends BaseAdminController $order['total_num'] = 0; $total_price=0; foreach ($data as $key => &$value) { - $find = StoreProduct::where('id', $value->product_id)->find(); + if(in_array($order['store_id'],[17,18])){ + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); + }else{ + $find = StoreProduct::where('id', $value->product_id)->find(); + } $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; if($type==2){ diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index e723cf2a9..1578d14a1 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -61,12 +61,8 @@ class WarehouseProductController extends BaseAdminController } WarehouseProductLogic::add($data); } - - if (WarehouseProductLogic::hasError()) { - return $this->fail(WarehouseProductLogic::getError()); - } else { - return $this->success('添加成功', [], 1, 1); - } + return $this->success('添加成功', [], 1, 1); + } @@ -95,11 +91,8 @@ class WarehouseProductController extends BaseAdminController { $params = (new WarehouseProductValidate())->post()->goCheck('delete'); WarehouseProductLogic::delete($params); - if (WarehouseProductLogic::hasError()) { - return $this->fail(WarehouseProductLogic::getError()); - } else { - return $this->success('删除成功', [], 1, 1); - } + return $this->success('删除成功', [], 1, 1); + } @@ -116,6 +109,17 @@ class WarehouseProductController extends BaseAdminController return $this->data($result); } + /** + * @notes 结算 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function settlement(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::settlement($id); + return $this->success('结算成功', [], 1, 1); + } /** * 确认操作 */ diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index fb3586f91..af5b65560 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -80,21 +80,46 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $list = StoreProduct::where($this->searchWhere) ->alias('p') // 为 StoreProduct 表设置别名 ->limit($this->limitOffset, $this->limitLength) - ->field('p.id, p.store_name, p.image,p.stock as total_stock, + ->field('p.id, p.store_name, p.image,p.stock as total_stock,p.unit,p.total_price, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.delete_time IS NULL) AS total_purchase, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') ->order($this->sortOrder) ->select() ->each(function ($item) { // 计算总库存 - $item->total_completed_amount=$item->total_completed_amount??0; - $item->warehouse_stock=$item->warehouse_stock??0; - $item->total_outstanding_amount=$item->total_outstanding_amount??0; - $item->total_purchase=$item->total_purchase??0; + $unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); + if($item->total_stock){ + $item->total_stock=bcadd($item->total_stock??0,$item->warehouse_stock??0,2).'|'.$unit_name; + }else{ + $item->total_stock=''; + } + $item->sales=$item->sales.'|'.$unit_name; + $item->store_stock=$item->store_stock.'|'.$unit_name; + $item->warehouse_stock=$item->warehouse_stock.'|'.$unit_name; + if($item->total_completed_amount){ + $item->total_completed_amount=$item->total_completed_amount.'元'; + }else{ + $item->total_completed_amount='0元'; + } + if($item->total_outstanding_amount){ + $item->total_outstanding_amount=$item->total_outstanding_amount.'元'; + }else{ + $item->total_outstanding_amount='0元'; + } + if($item->total_purchase){ + $item->total_purchase=$item->total_purchase.'元'; + }else{ + $item->total_purchase='0元'; + } + if($item->total_price){ + $item->total_price=$item->total_price.'元'; + }else{ + $item->total_price='0元'; + } }) ->toArray(); return $list; diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 7681a721d..3feb38d73 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -12,6 +12,7 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\lists\ListsExcelInterface; use app\common\lists\ListsSortInterface; +use app\common\model\store_product\StoreProduct; /** * 门店商品辅助表 @@ -65,6 +66,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { $class_all = $this->request->get('class_all'); + $export=$this->request->get('export'); $where = []; if ($class_all) { $arr = Cate::where('pid', $class_all)->column('id'); @@ -81,17 +83,20 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI $this->searchWhere[] = $where; } return StoreBranchProduct::where($this->searchWhere) - ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information']) + ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price']) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) ->limit($this->limitOffset, $this->limitLength) ->order($this->sortOrder) ->select() - ->each(function ($item) { + ->each(function ($item) use($export) { $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + if($export==2){ + $item['total_price'] = bcmul($item['purchase'],$item['stock'],2); + } return $item; }) ->toArray(); @@ -138,6 +143,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function setExcelFields(): array { $data = [ + 'product_id' => '商品ID', 'store_name' => '商品名称', 'store_info' => '规格', 'unit_name' => '单位', @@ -149,6 +155,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI 'vip_price' => '会员价', 'price' => '零售价', 'bar_code' => '条码', + 'total_price' => '价值', ]; return $data; } diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index d083b379e..2ab7640cd 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -11,13 +11,14 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\user\User; +use app\common\lists\ListsExcelInterface; /** * 订单列表列表 * Class StoreOrderLists * @package app\admin\listsstore_order */ -class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface +class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -30,7 +31,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','is_merge'], + '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge','uid'], 'between_time' => 'create_time' ]; } @@ -62,7 +63,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $query->whereIn('status', $status); } }) - ->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']) + ->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','refund_price']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { @@ -119,4 +120,38 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface }) ->count(); } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'id' => 'ID', + 'order_id'=>'订单号', + 'store_name'=>'门店', + 'nickname' => '用户', + 'total_price' => '总金额', + 'pay_price' => '实际支付', + 'status_name' => '状态', + 'refund_price' => '退款金额', + 'pay_time' => '支付时间', + ]; + return $data; + } } diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index dd9234c10..2c712c047 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -13,6 +13,8 @@ use app\common\lists\ListsExcelInterface; use app\common\model\store_category\StoreCategory; use app\common\model\store_order\StoreOrder; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\system_store\SystemStore; +use app\common\model\user\User; /** * 订单购物详情列表 @@ -49,21 +51,41 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('oid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) + ->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); if($find){ + if($item['uid']>0){ + $user=User::where('id',$item['uid'])->field('real_name,mobile')->find(); + if($user){ + if($user['real_name']!=''){ + $item['nickname']=$user['real_name']; + }else{ + $item['nickname']=$user['mobile']; + } + }else{ + $item['nickname']='无'; + } + }else{ + $item['nickname']='无'; + } $item['image']=$find['image'];//商品图片 + $item['system_store']=SystemStore::where('id',$item['store_id'])->value('name')??""; $item['store_name']=$find['store_name'];//商品名称 $item['store_info']=$find['store_info'];//商品规格 $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; }else{ $item['image']='';//商品图片 $item['unit_name']='';//商品图片 $item['cate_name']='';//商品图片 $item['store_name']='';//商品名称 $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['nickname']=''; + $item['system_store']=''; + $item['cart_info']=[]; } return $item; //返回处理后的数据。 }) @@ -108,12 +130,15 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI { $data=[ 'store_name' => '商品名称', + 'system_store' => '门店', + 'nickname' => '用户', 'store_info' => '规格', 'unit_name' => '单位', 'cate_name' => '分类', 'cart_num' => '数量', 'price' => '单价', 'total_price' => '总价', + 'create_time' => '时间', ]; return $data; } diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php index 8874e9358..6d5716796 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php @@ -63,31 +63,36 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear if ($this->request->get('start_time') == '') { $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; } - $this->searchWhere[]=['is_pay','=',1]; - $this->searchWhere[]=['status','>=',0]; + $is_group=$this->request->get('is_group'); + $this->searchWhere[] = ['is_pay', '=', 1]; + $this->searchWhere[] = ['status', '>=', 0]; $query = StoreOrderCartInfo::where($this->searchWhere); - if ($this->request->get('is_group') == 1) { + if ($is_group == 1) { $query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']); } else { - $query->field('store_id,product_id,price,total_price,cart_num'); + $query->field('store_id,product_id,price,total_price,cart_num,create_time'); } return $query->limit($this->limitOffset, $this->limitLength) - ->select()->each(function ($item) { + ->select()->each(function ($item) use($is_group){ $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find(); if ($find) { $item['image'] = $find['image']; //商品图片 - $item['store_name'] = $find['store_name']; //商品名称 + if($is_group==1){ + $item['store_name'] = $find['store_name'].'-'.$item['create_time']; //商品名称 + }else{ + $item['store_name'] = $find['store_name']; //商品名称 + } $item['store_info'] = $find['store_info']; //商品规格 - $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??''; - $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??''; - $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??''; - }else{ - $item['image']='';//商品图片 - $item['store_name']='';//商品名称 - $item['store_info']='';//商品规格-(数据库叫商品简介) - $item['unit_name']='';// - $item['cate_name']='';// - $item['system_store']='';// + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? ''; + $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name') ?? ''; + } else { + $item['image'] = ''; //商品图片 + $item['store_name'] = ''; //商品名称 + $item['store_info'] = ''; //商品规格-(数据库叫商品简介) + $item['unit_name'] = ''; // + $item['cate_name'] = ''; // + $item['system_store'] = ''; // } return $item; //返回处理后的数据。 }) @@ -130,16 +135,31 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear */ public function setExcelFields(): array { - $data = [ - 'system_store' => '门店', - 'store_name' => '商品名称', - 'store_info' => '规格', - 'unit_name' => '单位', - 'cate_name' => '分类', - 'cart_num' => '数量', - 'price' => '单价', - 'total_price' => '总价', - ]; + if ($this->request->get('is_group') == 1) { + $data = [ + 'system_store' => '门店', + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + } else { + $data = [ + 'system_store' => '门店', + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + 'create_time' => '时间', + ]; + } + return $data; } } diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index c4f4f50a5..85b0210f1 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -62,15 +62,50 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa } } return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) + ->field(['id', 'image', 'store_info', 'store_name', 'top_cate_id', 'two_cate_id', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { + $item['bar_code_two'] = ''; + if (in_array($item['unit'], [2, 21])) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; + } + $item['bar_code'] = ''; + $item['unit_names'] = '称重商品'; + } else { + if (strlen($item['bar_code']) < 10) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; + } + $item['bar_code'] = ''; + } + $item['unit_names'] = '标准商品'; + } + $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); $item['stock'] = bcadd($nums, $stock); - $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + $cate_name = ''; + $category_top = StoreCategory::where('id', $item['top_cate_id'])->value('name'); + if ($category_top != '') { + $cate_name = '/' . $category_top; + } + if (!$category_top) { + $category_two = StoreCategory::where('id', $item['two_cate_id'])->value('name'); + if ($category_two != '') { + $cate_name = $cate_name . '/' . $category_two; + } + } + $category_three = StoreCategory::where('id', $item['cate_id'])->value('name'); + if ($category_three) { + $cate_name = $cate_name . '/' . $category_three; + } + $item['cate_name'] = $cate_name; + // $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); return $item; })?->toArray(); } @@ -84,8 +119,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa */ public function count(): int { - $export=$this->request->get('export'); - if($export==1){ + $export = $this->request->get('export'); + if ($export == 1) { $class_all = $this->request->get('class_all'); if ($class_all) { //查3级别的 @@ -122,14 +157,18 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function setExcelFields(): array { $data = [ + 'id' => '商品id', + 'unit_names' => '计价方式', 'store_name' => '商品名称', - 'cate_name'=>'分类', - 'unit_name'=>'单位', + 'cate_name' => '分类', + 'unit_name' => '单位', + 'store_info' => '规格', 'stock' => '库存', 'purchase' => '采购价', 'cost' => '商户', 'price' => '零售', 'bar_code' => '条码', + 'bar_code_two' => '自编码', ]; return $data; } diff --git a/app/admin/lists/supplier/SupplierLists.php b/app/admin/lists/supplier/SupplierLists.php index a9321cc6b..c0757cda9 100644 --- a/app/admin/lists/supplier/SupplierLists.php +++ b/app/admin/lists/supplier/SupplierLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\supplier; use app\admin\lists\BaseAdminDataLists; use app\common\model\supplier\Supplier; use app\common\lists\ListsSearchInterface; - +use app\common\model\warehouse_product\WarehouseProduct; /** * 供应链列表 @@ -47,7 +47,10 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface ->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item) { + $item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price'); + $item->total_outstanding_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',0)->sum('total_price'); + }) ->toArray(); } diff --git a/app/admin/lists/user/UserLists.php b/app/admin/lists/user/UserLists.php index a419056cc..e94de5530 100644 --- a/app/admin/lists/user/UserLists.php +++ b/app/admin/lists/user/UserLists.php @@ -29,6 +29,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsS '=' => ['store_id','user_ship','is_disable'], '%like%' => ['account','mobile'], '%pipe_like%' => ['nickname'=>'nickname|real_name'], + 'between_time' => 'vip_time' ]; } diff --git a/app/admin/lists/user_recharge/UserRechargeLists.php b/app/admin/lists/user_recharge/UserRechargeLists.php index c1e7a1ee3..01d0a4670 100644 --- a/app/admin/lists/user_recharge/UserRechargeLists.php +++ b/app/admin/lists/user_recharge/UserRechargeLists.php @@ -7,13 +7,14 @@ use app\admin\lists\BaseAdminDataLists; use app\common\model\user_recharge\UserRecharge; use app\common\lists\ListsSearchInterface; use app\common\model\user\User; +use app\common\lists\ListsExcelInterface; /** * 充值记录列表 * Class UserRechargeLists * @package app\admin\listsuser_recharge */ -class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface +class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -88,4 +89,34 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa return UserRecharge::where($this->searchWhere)->count(); } + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'id' => 'ID', + 'order_id'=>'订单号', + 'nickname' => '用户', + 'price' => '实际支付', + 'paid_name' => '状态', + 'pay_time' => '支付时间', + ]; + return $data; + } } \ No newline at end of file diff --git a/app/admin/lists/warehouse_order/WarehouseOrderLists.php b/app/admin/lists/warehouse_order/WarehouseOrderLists.php index 543c26ca7..491184e7b 100644 --- a/app/admin/lists/warehouse_order/WarehouseOrderLists.php +++ b/app/admin/lists/warehouse_order/WarehouseOrderLists.php @@ -29,7 +29,8 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter public function setSearch(): array { return [ - '='=>['financial_pm'] + '='=>['financial_pm','supplier_id','warehouse_id','store_id'], + 'between_time' => 'create_time' ]; } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 419199631..c36d44e23 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt public function setSearch(): array { return [ - '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id'], + '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id','is_pay'], 'between_time' => 'create_time' ]; } @@ -71,7 +71,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } } return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time']) + ->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { @@ -106,6 +106,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } } else { $item->store_name = ''; + $item->image = ''; + $item->price = ''; } if ($item->warehouse_id) { $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); @@ -114,6 +116,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } if ($item->supplier_id) { $item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name'); + }else{ + $item->supplier_name = ''; } $item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : ''; $item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : ''; diff --git a/app/admin/logic/ConfigLogic.php b/app/admin/logic/ConfigLogic.php index a2b705d0c..44cd45dc8 100644 --- a/app/admin/logic/ConfigLogic.php +++ b/app/admin/logic/ConfigLogic.php @@ -18,6 +18,7 @@ use app\common\logic\BaseLogic; use app\common\model\Config; use app\common\model\dict\DictData; use app\common\service\{FileService, ConfigService}; +use support\exception\BusinessException; use think\facade\Db; /** @@ -46,10 +47,9 @@ class ConfigLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -73,10 +73,9 @@ class ConfigLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/app_update/AppUpdateLogic.php b/app/admin/logic/app_update/AppUpdateLogic.php index c32200227..c4e2921f0 100644 --- a/app/admin/logic/app_update/AppUpdateLogic.php +++ b/app/admin/logic/app_update/AppUpdateLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\app_update; use app\common\model\app_update\AppUpdate; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,10 +41,9 @@ class AppUpdateLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -71,10 +71,9 @@ class AppUpdateLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/auth/AdminLogic.php b/app/admin/logic/auth/AdminLogic.php index 0f92fa397..bff5eb111 100644 --- a/app/admin/logic/auth/AdminLogic.php +++ b/app/admin/logic/auth/AdminLogic.php @@ -24,6 +24,7 @@ use app\common\model\auth\AdminRole; use app\common\model\auth\AdminSession; use app\common\cache\AdminTokenCache; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; use think\facade\Db; @@ -70,10 +71,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -138,10 +138,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -177,10 +176,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/auth/RoleLogic.php b/app/admin/logic/auth/RoleLogic.php index 8146899f0..099ebeedc 100644 --- a/app/admin/logic/auth/RoleLogic.php +++ b/app/admin/logic/auth/RoleLogic.php @@ -20,6 +20,7 @@ use app\common\{ logic\BaseLogic, model\auth\SystemRoleMenu }; +use support\exception\BusinessException; use think\facade\Db; @@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/delivery_service/DeliveryServiceLogic.php b/app/admin/logic/delivery_service/DeliveryServiceLogic.php index c9a1eba72..99f671683 100644 --- a/app/admin/logic/delivery_service/DeliveryServiceLogic.php +++ b/app/admin/logic/delivery_service/DeliveryServiceLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\delivery_service; use app\common\model\delivery_service\DeliveryService; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -37,10 +38,9 @@ class DeliveryServiceLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -65,10 +65,9 @@ class DeliveryServiceLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/dept/DeptLogic.php b/app/admin/logic/dept/DeptLogic.php index d39e42b2b..e7e37737c 100644 --- a/app/admin/logic/dept/DeptLogic.php +++ b/app/admin/logic/dept/DeptLogic.php @@ -17,7 +17,7 @@ namespace app\admin\logic\dept; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\model\dept\Dept; - +use support\exception\BusinessException; /** * 部门管理逻辑 @@ -147,9 +147,8 @@ class DeptLogic extends BaseLogic 'sort' => $params['sort'] ?? 0 ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/dept/JobsLogic.php b/app/admin/logic/dept/JobsLogic.php index f23c0551f..ec137b68e 100644 --- a/app/admin/logic/dept/JobsLogic.php +++ b/app/admin/logic/dept/JobsLogic.php @@ -17,7 +17,7 @@ namespace app\admin\logic\dept; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\model\dept\Jobs; - +use support\exception\BusinessException; /** * 岗位管理逻辑 @@ -65,9 +65,8 @@ class JobsLogic extends BaseLogic 'remark' => $params['remark'] ?? '', ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/financial_transfers/FinancialTransfersLogic.php b/app/admin/logic/financial_transfers/FinancialTransfersLogic.php index d9b0577b3..f8dd223b2 100644 --- a/app/admin/logic/financial_transfers/FinancialTransfersLogic.php +++ b/app/admin/logic/financial_transfers/FinancialTransfersLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\financial_transfers; use app\common\model\financial_transfers\FinancialTransfers; use app\common\logic\BaseLogic; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; +use support\exception\BusinessException; use think\facade\Db; @@ -43,10 +44,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -76,10 +76,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -123,10 +122,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -138,7 +136,7 @@ class FinancialTransfersLogic extends BaseLogic $date = date('Y-m-d', $time); //获取一个月前的日期 $receivable = StoreCashFinanceFlow::whereMonth('create_time', $date)->where('status', 0)->sum('receivable'); if($receivable==0){ - self::setError('暂无法确认,还有未收取的现金'); + throw new BusinessException('暂无法确认,还有未收取的现金'); } Db::startTrans(); try { @@ -149,10 +147,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } diff --git a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php index 445a69b3d..bae2f627b 100644 --- a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php +++ b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php @@ -7,6 +7,7 @@ use app\common\model\inventory_transfer\InventoryTransfer; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use support\exception\BusinessException; use think\facade\Db; @@ -35,8 +36,7 @@ class InventoryTransferLogic extends BaseLogic if($params['one_type']==1){ $stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock'); if ($stock < $params['nums']) { - self::setError('调拨数量不能大于当前门店库存'); - return false; + throw new BusinessException('调拨数量不能大于当前门店库存'); } if($params['two_type']==1){ $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); @@ -51,8 +51,7 @@ class InventoryTransferLogic extends BaseLogic }elseif($params['one_type']==2){ $stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums'); if ($stock < $params['nums']) { - self::setError('调拨数量不能大于当前仓库库存'); - return false; + throw new BusinessException('调拨数量不能大于当前仓库库存'); } if($params['two_type']==1){ $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); @@ -65,8 +64,7 @@ class InventoryTransferLogic extends BaseLogic $two_before_nums = $stock_two; $two_after_nums = bcadd($stock_two, $params['nums']); }else{ - self::setError('调拨类型错误'); - return false; + throw new BusinessException('调拨类型错误'); } Db::startTrans(); @@ -97,8 +95,7 @@ class InventoryTransferLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -127,8 +124,7 @@ class InventoryTransferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/purchase_order/PurchaseOrderLogic.php b/app/admin/logic/purchase_order/PurchaseOrderLogic.php index 7f7ddfdbb..2ce0f4072 100644 --- a/app/admin/logic/purchase_order/PurchaseOrderLogic.php +++ b/app/admin/logic/purchase_order/PurchaseOrderLogic.php @@ -11,6 +11,7 @@ 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 support\exception\BusinessException; use think\facade\Db; @@ -181,8 +182,7 @@ class PurchaseOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -231,8 +231,7 @@ class PurchaseOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php b/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php index 44d5483a4..25089631f 100644 --- a/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php +++ b/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php @@ -6,6 +6,7 @@ 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_product\StoreProduct; +use support\exception\BusinessException; use think\facade\Db; class PurchaseOrderInfoLogic extends BaseLogic @@ -37,8 +38,7 @@ class PurchaseOrderInfoLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index d9b5fc996..32fd6aac4 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\purchase_product_offer; use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\logic\BaseLogic; use app\common\model\delivery_service\DeliveryService; +use support\exception\BusinessException; use think\facade\Db; @@ -53,8 +54,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -94,8 +94,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -106,8 +105,7 @@ class PurchaseProductOfferLogic extends BaseLogic { if($params['is_buyer']==1){ if($params['buyer_id']==''){ - self::setError('采购人不能为空'); - return false; + throw new BusinessException('采购人不能为空'); } $data['buyer_id']=$params['buyer_id']; $data['buyer_nums']=$params['buyer_nums']; @@ -120,8 +118,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } /** diff --git a/app/admin/logic/setting/CategoryLogic.php b/app/admin/logic/setting/CategoryLogic.php index 2afd91ffc..875d3d5df 100644 --- a/app/admin/logic/setting/CategoryLogic.php +++ b/app/admin/logic/setting/CategoryLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\setting; use app\common\model\setting\Category; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -43,8 +44,7 @@ class CategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -75,8 +75,7 @@ class CategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 60682f5bb..399e1dd0e 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -4,6 +4,7 @@ namespace app\admin\logic\statistic; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; @@ -48,12 +49,33 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + $pay_price=StoreOrder::where('paid',1)->where('refund_status',0)->sum('pay_price'); + // $refund_price=StoreOrder::where('paid',1)->sum('refund_price'); + $topData[] = [ + 'title' => '交易金额', + 'desc' => '平台发生交易的金额', + 'total_money' =>$pay_price, + 'value' => [], + 'type' => 1, + ]; + $number=StoreFinanceFlow::where('financial_type',3)->where('financial_pm',1)->sum('number'); + $topData[] = [ + 'title' => '获得利润', + 'desc' => '平台订单产生的手续费', + 'total_money' =>$number, + 'value' => [], + 'type' => 1, + ]; + // $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + $warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + + $storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' => $toreProduct['stock'], - 'cash_title' => $toreProduct['total_price'], + 'total_money' => bcadd($warehouseProductStorege['nums'], $storeBranchProduct['stock'], 2), + 'cash_title' => bcadd($warehouseProductStorege['total_price'], $storeBranchProduct['total_price'], 2), 'value' => [], 'type' => 1, ]; @@ -84,7 +106,6 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); $topData[] = [ 'title' => '总门店库存', 'desc' => '平台统计门店库存', @@ -190,14 +211,14 @@ class WarehouseLogic extends BaseLogic $list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray(); $count = StoreProduct::where('stock', '<', 0)->count(); } elseif ($parmas['type'] == 2) { - $where[]=['stock','<',0]; - if(isset($parmas['store_id']) && $parmas['store_id'] > 0){ - $where[]=['store_id','=',$parmas['store_id']]; + $where[] = ['stock', '<', 0]; + if (isset($parmas['store_id']) && $parmas['store_id'] > 0) { + $where[] = ['store_id', '=', $parmas['store_id']]; } - $store_arr=getenv('NO_STORE_STATISTICS'); - if($store_arr){ - $store_arr=explode(',',$store_arr); - $where[]=['store_id','not in',$store_arr]; + $store_arr = getenv('NO_STORE_STATISTICS'); + if ($store_arr) { + $store_arr = explode(',', $store_arr); + $where[] = ['store_id', 'not in', $store_arr]; } $list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select() ->each(function ($item) { @@ -217,19 +238,55 @@ class WarehouseLogic extends BaseLogic $count = WarehouseProductStorege::where('nums', '<', 0)->count(); } return ['lists' => $list, 'count' => $count]; - } + } /** * 负库存更新归0 */ public static function updateNegativeZero($parmas) { if ($parmas['type'] == 1) { - $res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 2) { - $res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 3) { - $res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]); + $res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]); } return $res; } + + public static function stockProductPrice($parmas) + { + $arr1 = WarehouseProductStorege::where('nums', '>', 0)->select(); + foreach ($arr1 as $k => $v) { + $find = StoreProduct::where('id', $v['product_id'])->find(); + if ($find && $find['price'] > 0) { + $total_price = bcmul($find['price'], $v['nums'], 2); + $price = $find['price']; + } else { + $total_price = 0; + $price = 0; + } + WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]); + } + + $arr2 = StoreBranchProduct::where('stock', '>', 0)->select(); + foreach ($arr2 as $k => $v) { + if ($v['price'] > 0) { + $total_price = bcmul($v['price'], $v['stock'], 2); + } else { + $total_price = 0; + } + StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]); + } + $arr3 = StoreProduct::where('stock', '>=', 0)->select(); + foreach ($arr3 as $k => $v) { + $stock = StoreBranchProduct::where('product_id', $v['id'])->where('stock', '>', 0)->sum('stock'); + $nums = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $v['id'])->sum('nums'); + $stock2 = bcadd($stock, $nums, 2); + bcmul($v['purchase'], $stock2, 2); + StoreProduct::where('id', $v['id'])->update(['stock' => $stock2, 'total_price' => $v]); + } + + return true; + } } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index 47fb6eda8..d3bf75c31 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -36,8 +36,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -52,8 +51,7 @@ class StoreBranchProductLogic extends BaseLogic { $StoreProduct = StoreBranchProduct::where('id', $params['id'])->find(); if ($params['status'] == 1 && $StoreProduct['price'] == 0) { - self::setError('商品价格不能为0,无法上架'); - return false; + throw new BusinessException('商品价格不能为0,无法上架'); } Db::startTrans(); try { @@ -67,10 +65,9 @@ class StoreBranchProductLogic extends BaseLogic StoreBranchProduct::where('id', $params['id'])->update($data); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('商品编辑失败:',$e->getMessage()); } } /** @@ -84,19 +81,22 @@ class StoreBranchProductLogic extends BaseLogic { Db::startTrans(); try { - $find = StoreProduct::where('id', $params['product_id'])->find(); - $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find(); + $find = StoreProduct::where('id', $params['product_id'])->find()->toArray(); + $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray(); if ($type == 1) { $stock = bcadd($find['stock'], $params['nums'], 2); $branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2); - StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); - StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); + StoreBranchProduct::update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=> $params['id']]); + StoreProduct::update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=> $params['product_id']]); + } else { $branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2); $stock = bcsub($find['stock'], $params['nums'], 2); - StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); - StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); + + StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=>$params['id']]); + StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]); + } Db::commit(); return true; @@ -116,8 +116,7 @@ class StoreBranchProductLogic extends BaseLogic { $stock = StoreBranchProduct::where('id', $params['id'])->value('stock'); if ($stock > 0) { - self::setError('商品库存不为0,无法删除'); - return false; + throw new BusinessException('商品库存不为0,无法删除'); } StoreBranchProduct::destroy($params['id']); return true; diff --git a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php index a8a1b4c24..e7787183a 100644 --- a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php +++ b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_cash_finance_flow; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -64,8 +64,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_category/StoreCategoryLogic.php b/app/admin/logic/store_category/StoreCategoryLogic.php index ba0b1c08b..5fd79536b 100644 --- a/app/admin/logic/store_category/StoreCategoryLogic.php +++ b/app/admin/logic/store_category/StoreCategoryLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_category; use app\common\model\store_category\StoreCategory; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class StoreCategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class StoreCategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_extract/StoreExtractLogic.php b/app/admin/logic/store_extract/StoreExtractLogic.php index f11d97ccd..70b5a4622 100644 --- a/app/admin/logic/store_extract/StoreExtractLogic.php +++ b/app/admin/logic/store_extract/StoreExtractLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_extract; use app\common\model\store_extract\StoreExtract; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreExtractLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreExtractLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php b/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php index d4dec2553..c39bd660e 100644 --- a/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php +++ b/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_finance_flow; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index a46665fe7..d340cad97 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -9,13 +9,17 @@ use app\api\logic\order\OrderLogic; use app\common\enum\PayEnum; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; +use app\common\logic\CommissionnLogic; use app\common\logic\PayNotifyLogic; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\user\User; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use support\exception\BusinessException; use think\facade\Db; @@ -42,17 +46,19 @@ class StoreOrderLogic extends BaseLogic $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; $v['cart_num'] = $v['stock']; - StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['price']]); + if(in_array($params['store_id'],[17,18])){ + StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]); + } unset($v['id']); $res = CartLogic::add($v); $cartId[] = $res['id']; } $user = User::where('id', $params['user_id'])->find(); - $params['shipping_type']=2; + $params['shipping_type'] = 2; $params['pay_type'] = 7; + $params['source'] =2;//后台下单 $order = OrderLogic::createOrder($cartId, null, $user, $params); return true; - } @@ -73,8 +79,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -112,35 +117,122 @@ class StoreOrderLogic extends BaseLogic public static function refund($detail, $params) { - //微信支付 - if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { - $money = (int)bcmul($detail['pay_price'], 100); - $refund = (new \app\common\logic\store_order\StoreOrderLogic()) - ->refund($params['order_id'], $money, $money); - if ($refund) { - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); + if (isset($params['product_arr']) && count($params['product_arr']) > 0) { + //微信支付 + if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { + $money = (int)bcmul($params['refund_price'], 100); + $pay_price = (int)bcmul($detail['pay_price'], 100); + $refund = (new \app\common\logic\store_order\StoreOrderLogic()) + ->refund($params['order_id'], $money, $pay_price); + if ($refund) { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } + } + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + $detail['refund_price']=$refund_price; + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + return '退款成功'; + } + } + //余额支付 采购款支付 + if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']); + return '退款成功'; + + } + //现金支付 + if ($detail['pay_type'] = PayEnum::CASH_PAY) { + PayNotifyLogic::cash_refund($params['order_id']); + return '退款成功'; + + } + return false; + + } else { + //微信支付 + if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { + $money = (int)bcmul($detail['pay_price'], 100); + $refund = (new \app\common\logic\store_order\StoreOrderLogic()) + ->refund($params['order_id'], $money, $money); + if ($refund) { + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); + return '退款成功'; + } + } + //余额支付 采购款支付 + if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + PayNotifyLogic::balance_purchase_refund($detail); + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); return '退款成功'; } + //现金支付 + if ($detail['pay_type'] = PayEnum::CASH_PAY) { + PayNotifyLogic::cash_refund($params['order_id']); + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); + return '退款成功'; + } + return false; + //todo 支付包支付 } - //余额支付 采购款支付 - if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - $money = bcmul($detail['pay_price'], 100); - $arr = [ - 'amount' => [ - 'refund' => $money - ] - ]; - PayNotifyLogic::refund($params['order_id'], $arr); - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); - return '退款成功'; + } + + public function refundProduct($detail, $params) + { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } } - //现金支付 - if ($detail['pay_type'] = PayEnum::CASH_PAY) { - PayNotifyLogic::cash_refund($params['order_id']); - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); - return '退款成功'; - } - return false; - //todo 支付包支付 + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); } } diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php index 84c9a84f0..711996c56 100644 --- a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -4,7 +4,13 @@ namespace app\admin\logic\store_order_cart_info; use app\admin\logic\statistic\TradeStatisticLogic; use app\common\logic\BaseLogic; +use app\common\model\dict\DictData; +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 support\exception\BusinessException; +use think\facade\Db; /** * 订单购物详情表逻辑 @@ -13,6 +19,151 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; */ class StoreOrderCartInfoLogic extends BaseLogic { + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + + $cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find(); + if($cart_info['is_pay']==1){ + throw new BusinessException('已支付订单无法追加'); + } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($cart_info['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } + foreach($params['product_arr'] as $k=>$v){ + $find=StoreProduct::where('id',$v['product_id'])->find(); + + $cart_select['total_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单总价 + + $cart_select['price'] = $v['price']; + $cart_select['cost'] = $v['price']; + $cart_select['vip'] = 0; + $cart_select['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称 + + $cart_select['purchase'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //成本 + $cart_select['pay_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单支付金额 + $cart_select['store_price'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //商户价 + $cart_select['vip_price'] = 0; //vip售价 + + $cart_select['product_id'] = $find['id']; + $cart_select['old_cart_id'] = 0; + $cart_select['cart_num'] = $v['cart_num']; + $cart_select['verify_code'] =$cart_info['verify_code']; + $cart_select['vip_frozen_price'] = 0; + $cart_select['store_info'] = $find['store_info']; + $cart_select['rose'] = $find['rose']; + + $cart_select['name'] = $find['store_name']; + $cart_select['image'] = $find['image']; + $aa[$k]['cart_info'] = json_encode($cart_select); + $aa[$k]['oid'] = $cart_info['oid']; + $aa[$k]['uid']=$cart_info['uid']; + $aa[$k]['product_id']=$find['id']; + $aa[$k]['verify_code']=$cart_info['verify_code']; + $aa[$k]['price']=$v['price']; + $aa[$k]['cart_num']=$v['cart_num']; + $aa[$k]['total_price']=$cart_select['pay_price']; + } + (new StoreOrderCartInfo())->saveAll($aa); + $total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count(); + + StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + d($e); + throw new BusinessException('编辑商品失败' . $e->getMessage()); + } + } + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $find = StoreOrderCartInfo::where('id', $params['id'])->find(); + if ($find) { + if($find['is_pay']==1){ + throw new BusinessException('已支付订单无法编辑'); + } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($find['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } + $find->cart_num = $params['cart_num']; + $find->total_price = bcmul($params['cart_num'], $find->price, 2); + $find->save(); + $total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count(); + StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException('编辑商品失败' . $e->getMessage()); + } + } + + /** + * @notes 删除商品 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function del(array $params): bool + { + Db::startTrans(); + try { + $find = StoreOrderCartInfo::where('id', $params['id'])->find(); + if ($find) { + if($find['is_pay']==1){ + throw new BusinessException('已支付订单无法删除'); + } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($find['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } + $find->delete_time=time(); + $find->save(); + $total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count(); + StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException('删除商品失败' . $e->getMessage()); + } + } public function curve($product_id, $start_time, $end_time) { $store_order_cart_info = new StoreOrderCartInfo(); @@ -29,13 +180,13 @@ class StoreOrderCartInfoLogic extends BaseLogic $totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)'); $totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey); - $value1=[]; - $value2=[]; - foreach($totalCartNum1['y'] as $k=>$v){ - $value1[]=$v; + $value1 = []; + $value2 = []; + foreach ($totalCartNum1['y'] as $k => $v) { + $value1[] = $v; } - foreach($totalCartNum2['y'] as $k=>$v){ - $value2[]=$v; + foreach ($totalCartNum2['y'] as $k => $v) { + $value2[] = $v; } $data = []; $data['xAxis'] = $totalCartNum1['x'] ?? []; @@ -45,9 +196,9 @@ class StoreOrderCartInfoLogic extends BaseLogic 'smooth' => 'true', 'type' => 'line', 'yAxisIndex' => 1, - 'value' =>$value1 - ] - ,[ + 'value' => $value1 + ], + [ 'name' => '金额', 'smooth' => 'true', 'type' => 'line', diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 87d7b22e4..693c32e9f 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -36,13 +36,25 @@ class StoreProductLogic extends BaseLogic */ public static function add(array $params): bool { + $count=count($params['cate_arr']); + $top_cate_id=0; + $two_cate_id=0; + if($count==3){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][1]; + }elseif($count==2){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][0]; + } Db::startTrans(); try { $data = [ 'store_name' => $params['store_name'], 'image' => $params['image'], 'store_info' => $params['store_info'] ?? '', - 'bar_code' =>$params['product_arr'][0]['bar_code'] ?? '', + 'bar_code' => $params['bar_code'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, 'cate_id' => $params['cate_id'], 'unit' => $params['product_arr'][0]['unit'], 'stock' => 0, @@ -57,8 +69,14 @@ class StoreProductLogic extends BaseLogic 'batch' => $params['batch'] ?? 0, 'store_batch' => $params['store_batch'] ?? 1, 'product_type' => $params['product_type'] ?? 0, - 'spec_type' => $params['spec_type'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, ]; + // if ($params['rose'] > 0) { + // $rose_price = bcmul($params['cost'], $params['rose'], 2); + // $data['price'] = bcadd($params['cost'], $rose_price, 2); + // } else { + // $data['price'] = 0; + // } $res = StoreProduct::create($data); $arr=[]; foreach($params['product_arr'] as $k=>$v){ @@ -76,8 +94,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - d($e); - throw new BusinessException($e->getMessage()); + throw new BusinessException('添加商品失败'.$e->getMessage()); } } @@ -146,11 +163,23 @@ class StoreProductLogic extends BaseLogic { Db::startTrans(); try { + $count=count($params['cate_arr']); + $top_cate_id=0; + $two_cate_id=0; + if($count==3){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][1]; + }elseif($count==2){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][0]; + } $data = [ 'store_name' => $params['store_name'], 'image' => $params['image'], 'bar_code' => $params['bar_code'] ?? '', 'store_info' => $params['store_info'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, 'cate_id' => $params['cate_id'], 'unit' => $params['unit'], 'stock' => $params['stock'], @@ -164,14 +193,14 @@ class StoreProductLogic extends BaseLogic 'store_batch' => $params['store_batch'] ?? 1, 'manufacturer_information' => $params['manufacturer_information'] ?? '', 'swap' => $params['swap'] ?? 0, - 'rose' => $params['rose'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, ]; - StoreProduct::where('id', $params['id'])->update($data); + StoreProduct::update($data,['id'=>$params['id']]); - $dealCate = self::dealChangeCate($params['cate_id']); + // $dealCate = self::dealChangeCate($params['cate_id']); //修改 - StoreBranchProduct::where('product_id', $params['id'])->update([ + StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id',[17,18])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], @@ -181,11 +210,13 @@ class StoreProductLogic extends BaseLogic 'manufacturer_information' => $params['manufacturer_information'] ?? '', 'store_info' => $params['store_info'] ?? '', 'cate_id' => $params['cate_id'], - 'top_cate_id' => $dealCate['top_cate_id'], - 'two_cate_id' => $dealCate['two_cate_id'], + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, + 'cate_id' => $params['cate_id'], 'bar_code' => $params['bar_code'], 'purchase' => $params['purchase'], 'rose' => $params['rose'] ?? 0, + 'status' => $params['is_show'] ?? 0, 'image' => $params['image'], 'store_batch' => $params['store_batch'] ?? 1, @@ -193,10 +224,10 @@ class StoreProductLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('编辑商品失败'.$e->getMessage()); + } } @@ -255,8 +286,8 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('删除失败'.$e->getMessage()); + } } @@ -264,6 +295,10 @@ class StoreProductLogic extends BaseLogic /**普通 */ public static function ordinary($product_arr, $store_id, $admin_id, $find) { + $res=StoreBranchProduct::where('store_id',$store_id)->where('product_id',$find['id'])->find(); + if($res){ + return $res; + } $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], @@ -331,8 +366,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; + throw new BusinessException('添加兑换商品失败'.$e->getMessage()); } } // else { diff --git a/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php index 32f3370dd..d6ba4c20d 100644 --- a/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php +++ b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_attr_value; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_product_unit/StoreProductUnitLogic.php b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php index 9ea649ec1..caa9bb9d8 100644 --- a/app/admin/logic/store_product_unit/StoreProductUnitLogic.php +++ b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_unit; use app\common\model\store_product_unit\StoreProductUnit; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class StoreProductUnitLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class StoreProductUnitLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/supplier/SupplierLogic.php b/app/admin/logic/supplier/SupplierLogic.php index ba686ab0b..907b352e2 100644 --- a/app/admin/logic/supplier/SupplierLogic.php +++ b/app/admin/logic/supplier/SupplierLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\supplier; use app\common\model\supplier\Supplier; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -41,8 +42,7 @@ class SupplierLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -71,8 +71,7 @@ class SupplierLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/system_store/SystemStoreLogic.php b/app/admin/logic/system_store/SystemStoreLogic.php index 4e68384b3..fbf3302e1 100644 --- a/app/admin/logic/system_store/SystemStoreLogic.php +++ b/app/admin/logic/system_store/SystemStoreLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\system_store; use app\common\model\system_store\SystemStore; use app\common\logic\BaseLogic; use app\common\model\system_store\SystemStoreStaff; +use support\exception\BusinessException; use think\facade\Db; use Webman\Config; @@ -70,8 +71,8 @@ class SystemStoreLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -137,8 +138,8 @@ class SystemStoreLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 03fac3aea..21eea8686 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -10,6 +10,7 @@ use app\common\logic\BaseLogic; use app\common\model\store_product\StoreProduct; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use support\exception\BusinessException; use think\facade\Db; @@ -44,10 +45,9 @@ class SystemStoreStorageLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -74,8 +74,8 @@ class SystemStoreStorageLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/tools/GeneratorLogic.php b/app/admin/logic/tools/GeneratorLogic.php index d88a288fe..dcef7c75f 100644 --- a/app/admin/logic/tools/GeneratorLogic.php +++ b/app/admin/logic/tools/GeneratorLogic.php @@ -21,6 +21,7 @@ use app\common\model\tools\GenerateTable; use app\common\service\generator\GenerateService; use support\Cache; use support\Container; +use support\exception\BusinessException; use think\facade\Db; @@ -78,8 +79,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -134,8 +134,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -157,8 +156,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -187,8 +185,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -228,8 +225,7 @@ class GeneratorLogic extends BaseLogic return ['file' => $zipFile]; } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -252,8 +248,7 @@ class GeneratorLogic extends BaseLogic return Container::get(GenerateService::class)->preview($table); } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user/UserFeedbackLogic.php b/app/admin/logic/user/UserFeedbackLogic.php index 4f291ebdc..aa612ccf3 100644 --- a/app/admin/logic/user/UserFeedbackLogic.php +++ b/app/admin/logic/user/UserFeedbackLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user; use app\common\logic\BaseLogic; use app\common\model\user\UserFeedback; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class UserFeedbackLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class UserFeedbackLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user/UserLogic.php b/app/admin/logic/user/UserLogic.php index 309d4ddc1..f28c21255 100644 --- a/app/admin/logic/user/UserLogic.php +++ b/app/admin/logic/user/UserLogic.php @@ -31,6 +31,7 @@ use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use think\facade\Db; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; /** @@ -69,10 +70,9 @@ class UserLogic extends BaseLogic Db::commit(); return $res; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -81,23 +81,19 @@ class UserLogic extends BaseLogic $user_ship=$params['user_ship']??0; if($user_ship==2){ if(!isset($params['village'])){ - self::setError('请设置村参数'); - return false; + throw new BusinessException('请设置村参数'); } $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'])->find(); if ($arr) { - self::setError('该区域已有村长请重新选择'); - return false; + throw new BusinessException('该区域已有村长请重新选择'); } }elseif($user_ship==3){ if(!isset($params['brigade'])){ - self::setError('请设置队参数'); - return false; + throw new BusinessException('请设置队参数'); } $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'] .' and brigade='.$params['brigade'])->find(); if($arr){ - self::setError('该区域已有队长请重新选择'); - return false; + throw new BusinessException('该区域已有队长请重新选择'); } } return true; @@ -148,8 +144,7 @@ class UserLogic extends BaseLogic return $res; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } /** @@ -179,8 +174,7 @@ class UserLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user_bill/UserBillLogic.php b/app/admin/logic/user_bill/UserBillLogic.php index f586146df..fd68aff01 100644 --- a/app/admin/logic/user_bill/UserBillLogic.php +++ b/app/admin/logic/user_bill/UserBillLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_bill; use app\common\model\user_bill\UserBill; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class UserBillLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class UserBillLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user_label/UserLabelLogic.php b/app/admin/logic/user_label/UserLabelLogic.php index d8a766b7c..af080ae80 100644 --- a/app/admin/logic/user_label/UserLabelLogic.php +++ b/app/admin/logic/user_label/UserLabelLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_label; use app\common\model\user_label\UserLabel; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class UserLabelLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,8 @@ class UserLabelLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/user_recharge/UserRechargeLogic.php b/app/admin/logic/user_recharge/UserRechargeLogic.php index 27fb78dc4..c60c1e8c3 100644 --- a/app/admin/logic/user_recharge/UserRechargeLogic.php +++ b/app/admin/logic/user_recharge/UserRechargeLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_recharge; use app\common\model\user_recharge\UserRecharge; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,8 @@ class UserRechargeLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -61,8 +62,8 @@ class UserRechargeLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/user_ship/UserShipLogic.php b/app/admin/logic/user_ship/UserShipLogic.php index cf804069d..40cd0650c 100644 --- a/app/admin/logic/user_ship/UserShipLogic.php +++ b/app/admin/logic/user_ship/UserShipLogic.php @@ -7,6 +7,7 @@ use app\common\model\user_ship\UserShip; use app\common\logic\BaseLogic; use app\common\model\user\User; use app\common\model\user\UserAddress; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,8 @@ class UserShipLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -67,8 +68,8 @@ class UserShipLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -106,8 +107,7 @@ class UserShipLogic extends BaseLogic $user_ship=$params['user_ship']??0; if($user_ship==2){ if(!isset($params['village'])){ - self::setError('请设置村参数'); - return false; + throw new BusinessException('请设置村参数'); } $arr=User::where('user_ship',$user_ship)->column('id'); if($arr){ @@ -116,14 +116,12 @@ class UserShipLogic extends BaseLogic if($params['uid']==$find['uid']){ return true; } - self::setError('该区域已有村长请重新选择'); - return false; + throw new BusinessException('该区域已有村长请重新选择'); } } }elseif($user_ship==3){ if(!isset($params['brigade'])){ - self::setError('请设置队参数'); - return false; + throw new BusinessException('请设置队参数'); } $arr=User::where('user_ship',$user_ship)->column('id'); if($arr){ @@ -132,8 +130,7 @@ class UserShipLogic extends BaseLogic if($params['uid']==$find['uid']){ return true; } - self::setError('该区域已有队长请重新选择'); - return false; + throw new BusinessException('该区域已有队长请重新选择'); } } } diff --git a/app/admin/logic/warehouse/WarehouseLogic.php b/app/admin/logic/warehouse/WarehouseLogic.php index 13568bdbe..88e24f4fc 100644 --- a/app/admin/logic/warehouse/WarehouseLogic.php +++ b/app/admin/logic/warehouse/WarehouseLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse; use app\common\model\warehouse\Warehouse; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -42,8 +43,8 @@ class WarehouseLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -73,8 +74,8 @@ class WarehouseLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php index 65539f214..8c9d262c3 100644 --- a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php +++ b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php @@ -6,6 +6,7 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\warehouse_order\WarehouseOrder; use app\common\logic\BaseLogic; use app\common\model\warehouse_product\WarehouseProduct; +use support\exception\BusinessException; use think\facade\Db; /** @@ -69,10 +70,9 @@ class WarehouseOrderLogic extends BaseLogic } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -88,8 +88,7 @@ class WarehouseOrderLogic extends BaseLogic { $find = WarehouseOrder::where('id', $params['id'])->find(); if (!$find) { - self::setError('订单不存在'); - return false; + throw new BusinessException('订单不存在'); } Db::startTrans(); try { @@ -128,8 +127,7 @@ class WarehouseOrderLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -145,8 +143,7 @@ class WarehouseOrderLogic extends BaseLogic { $count = WarehouseProduct::where('oid', $params['id'])->count(); if ($count >= 1) { - self::setError('该订单下还有商品没有删除,请先删除商品'); - return false; + throw new BusinessException('该订单下还有商品没有删除,请先删除商品'); } WarehouseOrder::destroy($params['id']); $find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index dc84e99bc..336528981 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -42,15 +42,22 @@ class WarehouseProductLogic extends BaseLogic $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); if ($storege) { if ($params['financial_pm'] == 0) { + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); + if (!$storeProduct) { + throw new BusinessException('商品不存在'); + } $after_nums = $storege['nums'] - $params['nums']; + $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); + // if ($after_nums < 0) { // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // } - WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update(); + WarehouseProductStorege::update(['nums'=>$after_nums, 'total_price' => $total_price],['id'=> $storege['id']]); + //门店加库存 $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); if (!$storeBranchProduct) { - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } @@ -62,28 +69,32 @@ class WarehouseProductLogic extends BaseLogic } else { $after_nums = $storege['nums'] + $params['nums']; if ($type == 1) { - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]); + WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price],['id'=>$storege['id']]); } } $before_nums = $storege['nums']; } else { $after_nums = $params['nums']; - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - WarehouseProductStorege::create([ + $data=[ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], 'nums' => $params['nums'], 'total_price'=>$total_price - ]); + ]; + if($params['financial_pm']==0){ + $data['nums']=-$params['nums']; + } + $storege=WarehouseProductStorege::create($data); } $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $data = [ @@ -208,8 +219,7 @@ class WarehouseProductLogic extends BaseLogic } elseif ($res['financial_pm'] == 0) { $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); if ($stock < $res['nums']) { - self::setError('商品库存不足,无法退回'); - return false; + throw new BusinessException('商品库存不足,无法退回'); } StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update(); @@ -223,9 +233,30 @@ class WarehouseProductLogic extends BaseLogic } return true; } - return false; + throw new BusinessException('没有查到出入库信息'); } + /** + * * @notes 结算 + * @param $id + * @return void + */ + public static function settlement($id){ + Db::startTrans(); + try { + $find=WarehouseProduct::where(['id'=>$id,'financial_pm'=>1,'is_pay'=>0])->find(); + if($find){ + $find->is_pay=1; + $find->save(); + } else{ + throw new BusinessException('没有查到出入库信息'); + } + Db::commit(); + } catch (\Throwable $th) { + Db::rollback(); + throw new BusinessException($th->getMessage()); + } + } /** * @notes 获取商品仓储信息详情 * @param $params diff --git a/app/admin/validate/supplier/SupplierValidate.php b/app/admin/validate/supplier/SupplierValidate.php index 92f4322c2..1aa1d6622 100644 --- a/app/admin/validate/supplier/SupplierValidate.php +++ b/app/admin/validate/supplier/SupplierValidate.php @@ -52,7 +52,7 @@ class SupplierValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['mer_name','phone','settle_cycle','address','mark','status']); + return $this->only(['mer_name','phone','settle_cycle','address']); } @@ -64,7 +64,7 @@ class SupplierValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','mer_name','phone','settle_cycle','address','mark','status']); + return $this->only(['id','mer_name','phone','settle_cycle','address']); } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 9add06bd8..4021947d1 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,9 +44,20 @@ class IndexController extends BaseApiController public function index() { - return json([1]); + return json(1); + + $financeFlow = new StoreFinanceFlow(); + $financeFlowLogic = new StoreFinanceFlowLogic(); + $select_1 = $financeFlow->where('id',16197)->select(); + + foreach ($select_1 as $k => $v) { + if ($v['other_uid'] > 0) { + $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); + } + } } + /** * @notes 下载文件 */ @@ -135,9 +146,8 @@ class IndexController extends BaseApiController $latitude = $params['lat']; $longitude = $params['long']; // 计算距离的SQL表达式 - $distanceSql = "SQRT(POW(69.1 * (latitude - {$latitude}), 2) + - POW(69.1 * ({$longitude} - longitude) * COS(latitude / 57.3), 2))"; - $find = SystemStore::field("id, name,abbreviation, {$distanceSql} AS distance") + $distanceExpr = "6371 * 2 * ASIN(SQRT(POWER(SIN(({$latitude} - abs(latitude)) * pi()/180 / 2), 2) + COS({$latitude} * pi()/180) * COS(abs(latitude) * pi()/180) * POWER(SIN(({$longitude} - longitude) * pi()/180 / 2), 2)))"; + $find = SystemStore::field("id, name,abbreviation, {$distanceExpr} AS distance") ->where('is_show', '=', 1) ->where('latitude', '<>', '') ->where('longitude', '<>', '') diff --git a/app/api/controller/LoginController.php b/app/api/controller/LoginController.php index a2e35b993..ece536175 100644 --- a/app/api/controller/LoginController.php +++ b/app/api/controller/LoginController.php @@ -19,9 +19,6 @@ class LoginController extends BaseApiController { $params = (new LoginAccountValidate())->post()->goCheck(); $result = LoginLogic::login($params); - if (false === $result) { - return $this->fail(LoginLogic::getError()); - } return $this->success('', $result); } /** @@ -44,9 +41,6 @@ class LoginController extends BaseApiController { $params = (new WechatLoginValidate())->post()->goCheck('mnpLogin'); $res = LoginLogic::mnpLogin($params); - if (false === $res) { - return $this->fail(LoginLogic::getError()); - } $res = LoginLogic::dealStaff($res); return $this->success('', $res); } @@ -63,9 +57,6 @@ class LoginController extends BaseApiController $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth"); $params['user_id'] = $this->userId; $result = LoginLogic::mnpAuthLogin($params); - if ($result === false) { - return $this->fail(LoginLogic::getError()); - } return $this->success('绑定成功', [], 1, 1); } @@ -79,9 +70,6 @@ class LoginController extends BaseApiController { $params = $this->request->post(); $result = LoginLogic::updateUser($params, $this->userId); - if ($result === false) { - return $this->fail(LoginLogic::getError()); - } return $this->success('操作成功', [], 1, 0); } diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index c5f070326..90b370357 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -6,8 +6,9 @@ use app\api\logic\order\CartLogic; use app\api\validate\CartValidate; use app\api\controller\BaseApiController; use app\api\lists\order\CartList; +use app\api\lists\order\CartWholesaleList; use app\common\model\order\Cart; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; class CartController extends BaseApiController @@ -16,7 +17,13 @@ class CartController extends BaseApiController { return $this->dataLists(new CartList()); } + /** + * 批发商品列表 + */ + public function wholesale_lists(){ + return $this->dataLists(new CartWholesaleList()); + } /** * @notes 添加购物车 */ @@ -25,18 +32,16 @@ class CartController extends BaseApiController $params = (new CartValidate())->post()->goCheck('add'); $params['uid'] = $this->request->userId; $result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find(); - + $params['cart_num']=bcadd($params['cart_num'],0,2); //判断起批发价 - $branchProduct = StoreBranchProduct::where( + $branchProduct = StoreProduct::where( [ - 'product_id' => $params['product_id'], - 'store_id' => $params['store_id'] + 'id' => $params['product_id'], ] )->find(); if (!$branchProduct) { return $this->fail('商品不存在'); } - $params['cart_num']=intval($params['cart_num']); if ($params['cart_num'] < $branchProduct['batch']) { return $this->fail('起批发量低于最低值' . $branchProduct['batch']); } @@ -85,12 +90,23 @@ class CartController extends BaseApiController { $params = (new CartValidate())->post()->goCheck('change'); $params['uid'] = $this->request->userId; - $params['cart_num']=intval($params['cart_num']); + $params['cart_num']=bcadd($params['cart_num'],0,2); + if (convertNumber($params['cart_num']) === false) { + $branchProduct = StoreProduct::where( + [ + 'id' => $params['product_id'], + ] + )->find(); + $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); + if ($is_bulk == 0) { + return $this->fail('非计量商品,不能有小数,请编辑购物车'); + } + } $res = CartLogic::edit($params, 'dec'); if ($res) { return $this->success('修改成功'); } else { - return $this->fail(CartLogic::getError()); + return $this->fail('修改失败'); } } @@ -105,7 +121,7 @@ class CartController extends BaseApiController if ($res) { return $this->success('删除成功'); } else { - return $this->fail(CartLogic::getError()); + return $this->fail('删除失败'); } } } diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 76b788483..b50eaa188 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -105,13 +105,6 @@ class OrderController extends BaseApiController $params = $this->request->post(); $user = User::where('id', $this->userId)->find(); $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params); - if ($res == false) { - $msg = OrderLogic::getError(); - if ($msg == '购物车为空') { - return $this->data([]); - } - return $this->fail(OrderLogic::getError()); - } return $this->data($res); } @@ -119,13 +112,6 @@ class OrderController extends BaseApiController { $params = (new OrderValidate())->post()->goCheck('cart'); $res = OrderLogic::checkLeft($params, $this->userId); - if (!$res) { - $msg = OrderLogic::getError(); - if ($msg == '购物车为空') { - return $this->data([]); - } - return $this->fail(OrderLogic::getError()); - } return $this->data($res); } @@ -230,8 +216,6 @@ class OrderController extends BaseApiController return $this->fail('支付方式错误'); } // return $this->data(['order_id' => $order->id]); - } else { - return $this->fail(OrderLogic::getError()); } } @@ -306,17 +290,11 @@ class OrderController extends BaseApiController } } $result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'] ?? 1, $redirectUrl); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } return $this->success('', $result); break; case PayEnum::WECHAT_PAY_BARCODE: //微信条码支付 $result = PaymentLogic::codepay($auth_code, $order); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); } else { @@ -336,9 +314,6 @@ class OrderController extends BaseApiController case PayEnum::ALIPAY_BARCODE: //支付宝条码支付 $result = PaymentLogic::ali_auth_code($auth_code, $order); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } if ($result['msg'] !== 'Success') { return $this->success('用户支付中'); } @@ -388,11 +363,8 @@ class OrderController extends BaseApiController { $params = $this->request->get(); $res = OrderLogic::frequentlyPurchase($params); - if (OrderLogic::hasError()) { - return $this->fail(OrderLogic::getError()); - } else { - return $this->data($res); - } + return $this->data($res); + } /** @@ -466,7 +438,7 @@ class OrderController extends BaseApiController if ($res) { return $this->success('核销成功'); } - return $this->fail('核销失败' . OrderLogic::getError()); + return $this->fail('核销失败'); } @@ -476,7 +448,7 @@ class OrderController extends BaseApiController $date = $this->request->get('date', date('Y-m-d')); $store_id = SystemStoreStaff::where('phone', $this->userInfo['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺'); + return $this->fail('该用户未绑定店铺'); } $where[] = ['store_id', '=', $store_id]; $where[] = ['paid', '=', 1]; diff --git a/app/api/controller/product/ProductController.php b/app/api/controller/product/ProductController.php index b7f5af617..2b4c4f771 100644 --- a/app/api/controller/product/ProductController.php +++ b/app/api/controller/product/ProductController.php @@ -3,11 +3,14 @@ namespace app\api\controller\product; use app\api\controller\BaseApiController; use app\api\lists\product\ProductLists; +use app\api\lists\product\ProductWholesaleLists; use app\api\lists\product\StoreProductLists; use app\common\model\system_store\SystemStoreStaff; class ProductController extends BaseApiController{ + public $notNeedLogin = ['lists']; + /** * 商品列表 */ @@ -16,6 +19,13 @@ class ProductController extends BaseApiController{ return $this->dataLists(new ProductLists()); } + /** + * 批发商品列表 + */ + public function wholesale_lists(){ + + return $this->dataLists(new ProductWholesaleLists()); + } /** * 商品列表 */ diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index e6335462b..cbf9528f2 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -89,20 +89,11 @@ class StoreController extends BaseApiController $params['create_uid']=$this->userId; if(isset($params['user_ship']) && in_array($params['user_ship'],[2,3])){ UserUserLogic::checkAddress($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } } $find=UserUserLogic::StoreAdd($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } }else{ if($find['user_ship']!=$params['user_ship'] && in_array($params['user_ship'],[2,3])){ UserUserLogic::checkAddress($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } } $find['real_name']=$params['real_name']; $find['label_id']=$params['label_id']??0; @@ -144,9 +135,6 @@ class StoreController extends BaseApiController $order['pay_price']=$order['price']; $order['attach']='recharge'; $result = PaymentLogic::codepay($auth_code, $order,'条码支付'); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { Cache::set('trade_state' . time(), json_encode($result)); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); @@ -181,9 +169,6 @@ class StoreController extends BaseApiController $order['pay_price']=$order['price']; $order['attach']='recharge'; $result = PaymentLogic::codepay($auth_code, $order,'条码支付'); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); } else { diff --git a/app/api/controller/user/AddressController.php b/app/api/controller/user/AddressController.php index 781f6f9e3..c19c26115 100644 --- a/app/api/controller/user/AddressController.php +++ b/app/api/controller/user/AddressController.php @@ -23,11 +23,8 @@ class AddressController extends BaseApiController $params = (new UserAddressValidate())->post()->goCheck('add'); $params['uid'] = $this->request->userId; $res=AddressLogic::add($params); - if(AddressLogic::hasError()){ - return $this->fail(AddressLogic::getError()); - }else{ - return $this->success('添加成功'); - } + return $this->success('添加成功'); + } /** * 商户给用户添加地址 @@ -62,9 +59,8 @@ class AddressController extends BaseApiController $params['uid'] = $this->request->userId; if(AddressLogic::edit($params)){ return $this->success('编辑成功'); - }else{ - return $this->fail(AddressLogic::getError()); } + return $this->fail('编辑失败'); } diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index d4ea0558e..82ee81392 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -42,9 +42,7 @@ class UserController extends BaseApiController $params = (new UserValidate())->post()->goCheck('getMobileByMnp'); $params['user_id'] = $this->userId; $result = UserLogic::getMobileByMnp($params); - if ($result === false) { - return $this->fail(UserLogic::getError()); - } + if ($result && is_numeric($result)) { $data = UserLogic::info($result); $userInfo = UserTokenService::setToken($result, 1); @@ -104,9 +102,6 @@ class UserController extends BaseApiController $order = UserLogic::recharge($params); $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } return $this->success('', $result); } diff --git a/app/api/controller/user/UserFeedbackController.php b/app/api/controller/user/UserFeedbackController.php index 46cedd303..1a680551b 100644 --- a/app/api/controller/user/UserFeedbackController.php +++ b/app/api/controller/user/UserFeedbackController.php @@ -30,6 +30,6 @@ if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(UserFeedbackLogic::getError()); + return $this->fail('添加失败'); } } diff --git a/app/api/controller/user/UserVisitController.php b/app/api/controller/user/UserVisitController.php index d777c094a..362f51455 100644 --- a/app/api/controller/user/UserVisitController.php +++ b/app/api/controller/user/UserVisitController.php @@ -30,8 +30,6 @@ class UserVisitController extends BaseApiController if (true === $result) { return $this->success('ok'); } - return $this->fail(UserVisitLogic::getError()); - } @@ -54,7 +52,6 @@ class UserVisitController extends BaseApiController if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(UserVisitLogic::getError()); } diff --git a/app/api/controller/user_product_storage/UserProductStorageController.php b/app/api/controller/user_product_storage/UserProductStorageController.php index 806a56204..eb73615b8 100644 --- a/app/api/controller/user_product_storage/UserProductStorageController.php +++ b/app/api/controller/user_product_storage/UserProductStorageController.php @@ -38,9 +38,6 @@ class UserProductStorageController extends BaseApiController $store_id=$params['store_id']; $times=$params['times']; UserProductStorageLogic::supply($info,$uid,$store_id,0,$times); - if(UserProductStorageLogic::hasError()){ - return $this->fail(UserProductStorageLogic::getError()); - } return $this->success('操作成功'); } } \ No newline at end of file diff --git a/app/api/controller/user_ship/UserShipController.php b/app/api/controller/user_ship/UserShipController.php index 3e6afa1b9..af297a228 100644 --- a/app/api/controller/user_ship/UserShipController.php +++ b/app/api/controller/user_ship/UserShipController.php @@ -31,10 +31,7 @@ class UserShipController extends BaseApiController public function is_user_ship(){ $data=$this->request->post(); UserShipLogic::user_ship($data); - if(UserShipLogic::hasError()){ - return $this->fail(UserShipLogic::getError()); - }else{ - return $this->success('ok'); - } + return $this->success('ok'); + } } \ No newline at end of file diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index 8157169f4..87644e174 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -6,7 +6,7 @@ namespace app\api\lists\cate; use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; use app\common\lists\ListsSearchInterface; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\Request; use think\facade\Db; @@ -28,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'data', 'store_id', 'sort'], + '=' => ['name', 'data', 'sort'], ]; } @@ -45,19 +45,23 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { $level = Request()->get('level', 1); + $source = Request()->get('source'); $pid = $this->request->get('pid',0); // $this->searchWhere[] = ['stock', '>', 0]; - $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['is_show', '=', 1]; + if($source && $source==4){ + $this->searchWhere[] = ['product_type', '=', 5]; + } if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } $lists = []; @@ -85,14 +89,14 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface $pid = $this->request->get('pid',0); if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } return Cate::where('id', 'in', $cate_arr)->count(); diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index a16c31e08..e734eb108 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -9,7 +9,7 @@ use app\common\model\order\Cart; use app\common\lists\ListsExtendInterface; use app\common\model\Config; use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; @@ -65,14 +65,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists ->toArray(); $off_activity = Config::where('name', 'off_activity')->value('value'); $user_ship = User::where('id', $userId)->value('user_ship'); - $field = 'product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; + $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; if (in_array($user_ship, [4, 6, 7])) { - $field = 'product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id'; + $field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; } $this->user_ship = $user_ship; $this->off_activity = $off_activity; foreach ($list as $key => &$item) { - $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) + $find = StoreProduct::where(['id' => $item['product_id']]) ->field($field) ->find(); if ($find) { @@ -84,6 +84,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists } $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); + $item['batch'] = $find['batch']; $item['imgs'] = $find['image']; $item['price'] = $find['price']; $item['cost'] = $find['cost']; diff --git a/app/api/lists/order/CartWholesaleList.php b/app/api/lists/order/CartWholesaleList.php new file mode 100644 index 000000000..766785d8d --- /dev/null +++ b/app/api/lists/order/CartWholesaleList.php @@ -0,0 +1,109 @@ +['store_id','source']]; + } + + + /** + * @notes 购物车列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @date 2024/04/27 11:26 + */ + public function lists($where = []): array + { + $userId = $this->request->userId; + if (!$userId) return []; + $where = [ + 'uid' => $userId, + 'is_pay' => 0 + ]; + $list = Cart::where($this->searchWhere)->where($where) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; + foreach ($list as $key => &$item) { + $find = StoreProduct::where(['id' => $item['product_id']]) + ->field($field) + ->find(); + if ($find) { + $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); + $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); + $item['batch'] = $find['batch']; + $item['imgs'] = $find['image']; + $item['price'] = $find['price']; + $item['cost'] = $find['cost']; + $item['goods_name'] = $find['store_name']; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + } + } + return $list; + } + + + /** + * @notes 购物车数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + $userId = $this->request->userId; + if (!$userId) return 0; + $where = [ + 'uid' => $userId, + 'is_pay' => 0 + ]; + return Cart::where($this->searchWhere)->where($where)->count(); + } + + public function extend() + { + $data = [ + 'off_activity' => $this->off_activity, + 'total_price' => $this->total_price, + 'msg' => '', + 'pay_price' => $this->total_price + ]; + return $data; + } +} diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index a08142f77..5e6652654 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -5,11 +5,8 @@ namespace app\api\lists\order; use app\admin\lists\BaseAdminDataLists; use app\common\lists\ListsSearchInterface; -use app\common\model\store_branch_product\StoreBranchProduct; 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 Picqer\Barcode\BarcodeGeneratorPNG; /** diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index d15d822f2..78a9fc274 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -6,11 +6,8 @@ namespace app\api\lists\product; use app\api\lists\BaseApiDataLists; use app\common\lists\ListsExtendInterface; use app\common\lists\ListsSortInterface; -use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; -use app\common\model\cate\Cate; use app\common\model\Config; use app\common\model\user\User; //use app\common\model\goods\GoodsLabel; @@ -35,7 +32,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis public function setSearch(): array { return [ - '=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'], + '=' => [ 'cate_id', 'top_cate_id', 'two_cate_id'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'], ]; } @@ -58,7 +55,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function setDefaultOrder(): array { - return ['price' => 'asc', 'id' => 'desc']; + return ['sort'=>'desc','price' => 'asc', 'id' => 'desc']; } /** @@ -72,6 +69,17 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function lists(): array { + $store_name=$this->request->get('store_name'); + if($store_name && $store_name!=''){ + if (preg_match('/^1234-/',$store_name)) { + foreach($this->searchWhere as $k=>$v){ + if($v[0]=='store_name|bar_code'){ + unset($this->searchWhere[$k]); + $this->searchWhere[$k]=['bar_code','=',$store_name]; + } + } + } + } $order = $this->request->get('order', ''); $field = $this->request->get('field', ''); if (empty($order) || empty($field)) { @@ -79,7 +87,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis } else { $order = [$field => $order]; } - $fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock,is_lack'; $off_activity = Config::where('name', 'off_activity')->value('value'); if ($off_activity == 1) { $tag = '赠10%品牌礼品券'; @@ -96,13 +104,13 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis if ($uid > 0) { $user_ship = User::where('id', $uid)->value('user_ship'); if (in_array($user_ship, [4, 6, 7])) { - $fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock,is_lack'; } } $this->off_activity = $off_activity; - $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['is_show', '=', 1]; // $this->searchWhere[] = ['stock', '>', 0]; - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) @@ -111,6 +119,9 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis if ($off_activity == 0 && $user_ship == 5 && $item['top_cate_id'] == 15189) { $item['price'] = $item['cost']; } + if($item['is_lack']==1){ + $tag='缺货'; + } $item['tag'] = $tag; return $item; }) @@ -126,7 +137,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function count(): int { - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->count(); } public function extend() diff --git a/app/api/lists/product/ProductWholesaleLists.php b/app/api/lists/product/ProductWholesaleLists.php new file mode 100644 index 000000000..75f3b58c4 --- /dev/null +++ b/app/api/lists/product/ProductWholesaleLists.php @@ -0,0 +1,117 @@ + [ 'cate_id', 'top_cate_id', 'two_cate_id'], + '%pipe_like%' => ['store_name' => 'store_name|bar_code'], + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['sell' => 'price', 'sales' => 'sales',]; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['price' => 'asc', 'id' => 'desc']; + } + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function lists(): array + { + + $order = $this->request->get('order', ''); + $field = $this->request->get('field', ''); + if (empty($order) || empty($field)) { + $order = $this->sortOrder; + } else { + $order = [$field => $order]; + } + $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + + $this->searchWhere[] = ['is_show', '=', 1]; + $this->searchWhere[] = ['product_type', '=', 5]; + // $this->searchWhere[] = ['stock', '>', 0]; + return StoreProduct::where($this->searchWhere) + ->field($fields) + ->with(['className', 'unitName']) + ->limit($this->limitOffset, $this->limitLength) + ->order($order) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + return StoreProduct::where($this->searchWhere) + ->count(); + } + public function extend() + { + $price = 'price'; + $op_price = 'price'; + $data = [ + 'off_activity' => $this->off_activity, + 'price' => $price, + 'op_price' => $op_price, + ]; + return $data; + } +} diff --git a/app/api/lists/product/StoreProductLists.php b/app/api/lists/product/StoreProductLists.php index f9c4b2d09..ee66cd1c3 100644 --- a/app/api/lists/product/StoreProductLists.php +++ b/app/api/lists/product/StoreProductLists.php @@ -7,7 +7,6 @@ use app\api\lists\BaseApiDataLists; use app\common\lists\ListsExtendInterface; use app\common\lists\ListsSortInterface; use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; use app\common\model\cate\Cate; @@ -72,22 +71,17 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface */ public function lists(): array { - $store_id= $this->request->__get('store_id'); - if($store_id){ - $this->searchWhere[] = ['store_id', '=', $store_id]; - } - - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $type=$this->request->get('type',0); if($type==1){ - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; }elseif($type==2){ - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; } $this->searchWhere[] = ['status', '=', 1]; // $this->searchWhere[] = ['stock', '>', 0]; - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) @@ -105,7 +99,7 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface */ public function count(): int { - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->count(); } } diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 9f52831f3..64c1d6c6b 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -48,62 +48,76 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function lists(): array { - $latitude = $this->request->get('latitude',''); - $longitude = $this->request->get('longitude',''); - $cart_id = $this->request->get('cart_id',''); -// if(empty($longitude) || empty($latitude)){ -// throw new Exception('缺失经纬度'); -// } - $where[]=['is_show','=',YesNoEnum::YES]; + $latitude = $this->request->get('latitude', ''); + $longitude = $this->request->get('longitude', ''); + $cart_id = $this->request->get('cart_id', ''); + // if(empty($longitude) || empty($latitude)){ + // throw new Exception('缺失经纬度'); + // } + $where[] = ['is_show', '=', YesNoEnum::YES]; $data = SystemStore::where($this->searchWhere)->where($where) - ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', - 'day_time','is_store','latitude','longitude','day_start','day_end','is_store' - ,'is_send','abbreviation' + ->field([ + 'id', + 'name', + 'phone', + 'detailed_address', + 'image', + 'is_show', + 'day_time', + 'is_store', + 'latitude', + 'longitude', + 'day_start', + 'day_end', + 'is_store', + 'is_send', + 'abbreviation' ]) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); - if($cart_id){ - if($latitude && $longitude){ - $cart_id = explode(',',$cart_id); - $cart_select = Cart::whereIn('id', $cart_id) - ->field('id,product_id,cart_num,store_id')->select()->toArray(); - foreach ($cart_select as $v) { - foreach ($data as &$values){ - $store = StoreBranchProduct::where([ - 'store_id'=>$values['id'], - 'product_id'=>$v['product_id'], - ])->field('id,store_name,stock')->withTrashed()->find(); - if(empty($store)){ - $store['stock'] =0; - } - $values['reservation'] = 0; - if($store['stock'] < $v['cart_num']){ - $values['reservation'] = 1; - } - $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); - } + if ($cart_id) { + if ($latitude && $longitude) { + foreach ($data as &$values) { + $values['distance'] = haversineDistance($values['latitude'], $values['longitude'], $latitude, $longitude); + $values['reservation'] = 1; } - }else{ - foreach ($data as &$values){ + + // $cart_id = explode(',',$cart_id); + // $cart_select = Cart::whereIn('id', $cart_id) + // ->field('id,product_id,cart_num,store_id')->select()->toArray(); + // foreach ($cart_select as $v) { + // foreach ($data as &$values){ + // $store = StoreBranchProduct::where([ + // 'store_id'=>$values['id'], + // 'product_id'=>$v['product_id'], + // ])->field('id,store_name,stock')->withTrashed()->find(); + // if(empty($store)){ + // $store['stock'] =0; + // } + // $values['reservation'] = 0; + // if($store['stock'] < $v['cart_num']){ + // } + // } + + // } + } else { + foreach ($data as &$values) { $values['distance'] = 0; } } - - }else{ - if($latitude && $longitude){ - foreach ($data as &$value){ - $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); - + } else { + if ($latitude && $longitude) { + foreach ($data as &$value) { + $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $latitude, $longitude); } - }else{ - foreach ($data as &$values){ + } else { + foreach ($data as &$values) { $values['distance'] = 0; } } - } usort($data, function ($a, $b) { @@ -121,8 +135,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function count(): int { - $where[]=['is_show','=',YesNoEnum::YES]; + $where[] = ['is_show', '=', YesNoEnum::YES]; return SystemStore::where($this->searchWhere)->where($where)->count(); } - -} \ No newline at end of file +} diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index fae9c37fe..bb5f57f66 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -27,7 +27,7 @@ use app\common\service\{ }; use app\common\model\user\{User, UserAuth}; use app\common\service\wechat\WeChatMnpService; - +use support\exception\BusinessException; use Webman\Config; /** @@ -63,8 +63,7 @@ class LoginLogic extends BaseLogic return true; } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -88,7 +87,7 @@ class LoginLogic extends BaseLogic $user = User::where($where)->findOrEmpty(); if ($user->isEmpty()) { - throw new \Exception('用户不存在'); + throw new BusinessException('用户不存在'); } //更新登录信息 @@ -121,8 +120,7 @@ class LoginLogic extends BaseLogic 'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']), ]; } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -214,9 +212,8 @@ class LoginLogic extends BaseLogic } return $userInfo; - } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -242,9 +239,8 @@ class LoginLogic extends BaseLogic // Db::commit(); return $userInfo; } catch (\Exception $e) { + throw new BusinessException($e->getMessage()); // Db::rollback(); - self::$error = $e->getMessage(); - return false; } } @@ -260,7 +256,7 @@ class LoginLogic extends BaseLogic { $user = User::findOrEmpty($userId); if ($user->isEmpty()) { - throw new \Exception('用户不存在'); + throw new BusinessException('用户不存在'); } $time = time(); @@ -348,7 +344,7 @@ class LoginLogic extends BaseLogic //先检查openid是否有记录 $isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty(); if (!$isAuth->isEmpty()) { - throw new \Exception('该微信已被绑定'); + throw new BusinessException('该微信已被绑定'); } if (isset($response['unionid']) && !empty($response['unionid'])) { @@ -356,7 +352,7 @@ class LoginLogic extends BaseLogic $userAuth = UserAuth::where(['unionid' => $response['unionid']]) ->findOrEmpty(); if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) { - throw new \Exception('该微信已被绑定'); + throw new BusinessException('该微信已被绑定'); } } @@ -456,8 +452,7 @@ class LoginLogic extends BaseLogic if($find){ $auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的 if($auth){ - self::$error ='该手机号已绑定'; - return false; + throw new BusinessException('该手机号已绑定'); }else{ UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]); } diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index df53b367a..67ad68b47 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -6,6 +6,7 @@ namespace app\api\logic\order; use app\common\model\order\Cart; use app\common\logic\BaseLogic; use app\common\model\store_product_log\StoreProductLog; +use support\exception\BusinessException; use think\facade\Db; @@ -27,10 +28,10 @@ class CartLogic extends BaseLogic */ public static function add(array $params) { - if ($params['store_id'] <= 0) { - self::setError('门店ID不能为空'); - return false; + if ($params['store_id'] < 0) { + throw new BusinessException('门店ID不能为空'); } + $source=$params['source'] ?? 0; Db::startTrans(); try { //check @@ -38,7 +39,8 @@ class CartLogic extends BaseLogic 'uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], - 'is_pay' => 0 + 'is_pay' => 0, + 'source' => $source, ])->field('id')->find(); if ($check) { Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num']) @@ -53,6 +55,7 @@ class CartLogic extends BaseLogic 'staff_id' => $params['staff_id'] ?? 0, 'cart_num' => $params['cart_num'], 'is_new' => $params['is_new'] ?? 0, + 'source' =>$source, ]); } StoreProductLog::create([ @@ -66,10 +69,9 @@ class CartLogic extends BaseLogic ]); Db::commit(); return $cart; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -85,18 +87,24 @@ class CartLogic extends BaseLogic { Db::startTrans(); try { - Cart::where([ - 'uid' => $params['uid'], - 'store_id' => $params['store_id'], - 'product_id' => $params['product_id'] - ]) - ->update(['cart_num' => $params['cart_num']]); + if(isset($params['type']) && $params['type']=='inc'){ + Cart::where([ + 'uid' => $params['uid'], + 'store_id' => $params['store_id'], + 'product_id' => $params['product_id'] + ])->inc('cart_num')->update(); + }else{ + Cart::where([ + 'uid' => $params['uid'], + 'store_id' => $params['store_id'], + 'product_id' => $params['product_id'] + ])->update(['cart_num' => $params['cart_num']]); + } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index dc6692c10..fb9ac27af 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -66,16 +66,17 @@ class OrderLogic extends BaseLogic */ static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0) { - if(empty($params['store_id']) || $params['store_id'] <= 0){ - self::setError('请选择门店'); - return false; + if (empty($params['store_id']) || $params['store_id'] <= 0) { + throw new BusinessException('请选择门店'); + } + $source=0; + if (isset($params['source']) && $params['source'] >0) { + $source=$params['source']; } - $where = ['is_pay' => 0]; - $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); + $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num,source')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } try { self::$total_price = 0; @@ -89,18 +90,21 @@ class OrderLogic extends BaseLogic self::$fresh_price = 0; //生鲜金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); - $field = 'product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; + $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); + if ($source == 2) { + $field = 'product_id,product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; + $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); + } else { + $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); + } if (!$find) { - self::setError('商品不存在'); - return false; + throw new BusinessException('商品不存在'); } if (convertNumber($v['cart_num']) == false) { $is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk'); if ($is_bulk == 0) { - self::setError('非计量商品,不能有小数,请编辑购物车'); - return false; + throw new BusinessException('非计量商品,不能有小数,请编辑购物车'); } } $StoreCategory = StoreCategory::where('id', $find['cate_id'])->find(); @@ -115,21 +119,26 @@ class OrderLogic extends BaseLogic } 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, 6, 7]))) { - $price = $find['cost']; - } else { - $price = $find['price']; - //单门店活动判断 - if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) { - $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price'); - if ($storeBranchPrice) { - $price = $storeBranchPrice; + if ($v['source'] != 4) { + if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { + $price = $find['cost']; + } else { + $price = $find['price']; + //单门店活动判断 + if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) { + $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price'); + if ($storeBranchPrice) { + $price = $storeBranchPrice; + } } } + if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { + $price = $find['cost']; + } + } else { + $price = $find['price']; } - if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { - $price = $find['cost']; - } + $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['vip'] = 0; @@ -172,6 +181,7 @@ class OrderLogic extends BaseLogic $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'); + $cart_select[$k]['total_price'] = $cart_select[$k]['pay_price']; 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); @@ -193,12 +203,11 @@ class OrderLogic extends BaseLogic $pay_price = self::$pay_price; // bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 //判断生鲜是否大于200 - if ($createOrder == 1 && self::$fresh_price > 0) { - if (self::$pay_price < 200) { - self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单'); - return false; - } - } + // if ($createOrder == 1 && self::$fresh_price > 0 &&$source!=2) { + // if (self::$pay_price < 200) { + // throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单'); + // } + // } if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) { $off_activity = 1; } @@ -222,7 +231,7 @@ class OrderLogic extends BaseLogic 'activities' => $off_activity, 'deduction_price' => self::$deduction_price, //抵扣金额 'frozen_money' => 0, //self::$frozen_money, //返还金额(活动关闭得时候有) - 'source' => 0, + 'source' => $source, 'is_storage' => $params['is_storage'] ?? 0, 'address_id' => 0, ]; @@ -230,9 +239,6 @@ class OrderLogic extends BaseLogic 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']; - } if (isset($params['store_id']) && $params['store_id'] > 0) { $store_id = $params['store_id']; @@ -256,10 +262,8 @@ class OrderLogic extends BaseLogic $currentDate = date('Y-m-d'); $alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days')); } - } catch (\Exception $e) { - d($e); - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'], 'alert' => $alert]; } @@ -276,17 +280,10 @@ class OrderLogic extends BaseLogic $params['order_id'] = $order_id; $params['verify_code'] = $verify_code; $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1); - if ($orderInfo == false) { - self::setError(self::getError()); - return false; - } - if (!$orderInfo) { - return false; - } $uid = $user['id'] ?? 0; $_order = $orderInfo['order']; if ($_order['pay_price'] == 0) { - throw new \Exception('支付金额不能为0'); + throw new BusinessException('支付金额不能为0'); } $_order['uid'] = $uid; $_order['spread_uid'] = $params['spread_uid'] ?? 0; @@ -305,8 +302,6 @@ class OrderLogic extends BaseLogic if ($uid > 0) { $address = UserAddress::where(['uid' => $uid])->find(); if ($address) { - $_order['real_name'] = $address['real_name']; - $_order['user_phone'] = $address['phone']; if ($address['area']) { $_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? ''; } @@ -327,7 +322,7 @@ class OrderLogic extends BaseLogic $_order['status'] = 1; } if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) { - throw new \Exception('余额不足'); + throw new BusinessException('余额不足'); } //生成核销码 // $generator = new BarcodeGeneratorPNG(); @@ -341,7 +336,7 @@ class OrderLogic extends BaseLogic $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; @@ -356,8 +351,7 @@ class OrderLogic extends BaseLogic return $order; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -378,8 +372,7 @@ class OrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $params['cart_id']) ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } $newArr = []; //检查购物车对比店铺得商品数量差异 @@ -447,12 +440,11 @@ class OrderLogic extends BaseLogic // 提交事务 Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { // 回滚事务 Db::rollback(); Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); - self::setError('支付失败' . $e->getMessage()); - return false; + throw new BusinessException('支付失败' . $e->getMessage()); } } @@ -467,11 +459,10 @@ class OrderLogic extends BaseLogic return []; } $goods_arr = array_unique($goods_id); - $select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); + $select = StoreProduct::where('id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); return $select->toArray(); - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -487,9 +478,6 @@ class OrderLogic extends BaseLogic $data[$k]['store_id'] = $v['store_id']; $data[$k]['staff_id'] = $v['staff_id']; $data[$k]['combination_id'] = 0; - $data[$k]['seckill_id'] = 0; - $data[$k]['bargain_id'] = 0; - $data[$k]['discount_id'] = 0; $data[$k]['status'] = 1; $data[$k]['staff_id'] = 0; $data[$k]['is_new'] = 0; @@ -511,10 +499,8 @@ class OrderLogic extends BaseLogic $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { - $find = StoreBranchProduct::where('product_id', $item['product_id'])->where('store_id', $find['store_id'])->find(); - if (empty($find)) { - $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); - } + $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); + $item['store_name'] = $find['store_name']; $item['nums'] = floatval($item['nums']); $item['image'] = $find['image']; @@ -584,8 +570,7 @@ class OrderLogic extends BaseLogic 'verify_code' => $params['verify_code'] ])->find(); if (empty($order)) { - self::setError('订单不存在'); - return false; + throw new BusinessException('订单不存在'); } Db::startTrans(); try { @@ -631,10 +616,9 @@ class OrderLogic extends BaseLogic } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -643,7 +627,7 @@ class OrderLogic extends BaseLogic { $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺请查看'); + throw new BusinessException('该用户未绑定店铺请查看'); } $query = StoreOrderCartInfo::alias('o') ->leftJoin('store_branch_product p', 'p.id = o.product_id') @@ -693,7 +677,7 @@ class OrderLogic extends BaseLogic $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺请查看'); + throw new BusinessException('该用户未绑定店铺请查看'); } //先查商品相似 @@ -785,7 +769,7 @@ class OrderLogic extends BaseLogic self::dealChangeCartInfo($refundOrder); // d($leftOrder,$refundOrder); Db::commit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { // 回滚事务 Db::rollback(); throw new BusinessException($e->getMessage()); diff --git a/app/api/logic/user/AddressLogic.php b/app/api/logic/user/AddressLogic.php index 694c1a16a..4a5dea6bc 100644 --- a/app/api/logic/user/AddressLogic.php +++ b/app/api/logic/user/AddressLogic.php @@ -4,6 +4,7 @@ namespace app\api\logic\user; use app\common\logic\BaseLogic; use app\common\model\user\UserAddress; +use support\exception\BusinessException; use think\facade\Db; /** @@ -48,10 +49,9 @@ class AddressLogic extends BaseLogic ]); Db::commit(); return $id; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -95,10 +95,9 @@ class AddressLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/api/logic/user/UserFeedbackLogic.php b/app/api/logic/user/UserFeedbackLogic.php index 42cba90e6..c1f53dacb 100644 --- a/app/api/logic/user/UserFeedbackLogic.php +++ b/app/api/logic/user/UserFeedbackLogic.php @@ -4,7 +4,8 @@ use app\common\logic\BaseLogic; use app\common\model\user\UserFeedback; - use think\facade\Db; +use support\exception\BusinessException; +use think\facade\Db; class UserFeedbackLogic extends BaseLogic { @@ -29,10 +30,10 @@ ]); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } } \ No newline at end of file diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index 8e609df0d..9bb617246 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -24,6 +24,7 @@ use app\common\{logic\BaseLogic, use app\common\logic\UserSignLogic; use app\common\model\user_label\UserLabel; use support\Cache; +use support\exception\BusinessException; use think\facade\Db; @@ -49,7 +50,7 @@ class UserLogic extends BaseLogic $response = (new WeChatMnpService())->getUserPhoneNumber($params['code']); $phoneNumber = $response['phone_info']['purePhoneNumber'] ?? ''; if (empty($phoneNumber)) { - throw new \Exception('获取手机号码失败'); + throw new BusinessException('获取手机号码失败'); } $user = User::where([ @@ -75,9 +76,8 @@ class UserLogic extends BaseLogic ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -211,7 +211,7 @@ class UserLogic extends BaseLogic $code = generateRandomCode(); $phone = User::where('id',$uid)->value('mobile'); if(empty($phone)){ - throw new \Exception('用户未设置手机号'); + throw new BusinessException('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code); diff --git a/app/api/logic/user/UserVisitLogic.php b/app/api/logic/user/UserVisitLogic.php index fa00f3e4d..dfefb9954 100644 --- a/app/api/logic/user/UserVisitLogic.php +++ b/app/api/logic/user/UserVisitLogic.php @@ -5,7 +5,8 @@ use app\common\logic\BaseLogic; use app\common\model\store_visit\StoreVisit; use app\common\model\user\UserVisit; - use think\facade\Db; +use support\Log; +use think\facade\Db; class UserVisitLogic extends BaseLogic { @@ -39,10 +40,9 @@ } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + Log::error('添加商品浏览失败:'.$e->getMessage()); } } @@ -70,10 +70,9 @@ } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + Log::error('添加用户访问失败:'.$e->getMessage()); } diff --git a/app/api/validate/LoginAccountValidate.php b/app/api/validate/LoginAccountValidate.php index daef936f5..e9f33c8bf 100644 --- a/app/api/validate/LoginAccountValidate.php +++ b/app/api/validate/LoginAccountValidate.php @@ -13,6 +13,7 @@ use app\common\service\sms\SmsDriver; use app\common\validate\BaseValidate; use app\common\model\user\User; use support\Cache; +use support\exception\BusinessException; use think\Exception; use Webman\Config; /** @@ -92,7 +93,7 @@ class LoginAccountValidate extends BaseValidate //账号安全机制,连续输错后锁定,防止账号密码暴力破解 $userAccountSafeCache = new UserAccountSafeCache(); if (!$userAccountSafeCache->isSafe()) { - return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'; + throw new BusinessException( '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'); } $where = []; @@ -106,22 +107,22 @@ class LoginAccountValidate extends BaseValidate ->findOrEmpty(); if ($userInfo->isEmpty()) { - return '用户不存在'; + throw new BusinessException( '用户不存在'); } if ($userInfo['is_disable'] === YesNoEnum::YES) { - return '用户已禁用'; + throw new BusinessException( '用户已禁用'); } if (empty($userInfo['password'])) { $userAccountSafeCache->record(); - return '用户不存在'; + throw new BusinessException( '用户不存在'); } $passwordSalt = Config::get('project.unique_identification'); if ($userInfo['password'] !== create_password($password, $passwordSalt)) { $userAccountSafeCache->record(); - return '密码错误'; + throw new BusinessException( '密码错误'); } $userAccountSafeCache->relieve(); @@ -147,10 +148,10 @@ class LoginAccountValidate extends BaseValidate } $code = Cache::get($remark); if(empty($code)){ - return '验证码不存在'; + throw new BusinessException( '验证码不存在'); } if (isset($data['code']) && $code != $data['code']) { - return '验证码错误'; + throw new BusinessException( '验证码错误'); } return true; diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 221d2e9ea..6590a2759 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -100,7 +100,7 @@ class CapitalFlowLogic extends BaseLogic * @param $mark * @return mixed */ - public function storeIncome($category, $linkType, $linkId, $amount, $mark = '') + public function storeIncome($category, $linkType, $linkId, $amount, $mark = '',$key='') { $model = new CapitalFlow(); $model->store_id = $this->store['id']; @@ -108,8 +108,8 @@ class CapitalFlowLogic extends BaseLogic $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; - $model->before_balance = $this->store['balance']; - $model->balance = bcadd($this->store['balance'], $amount, 2); + $model->before_balance = $this->store[$key]??0; + $model->balance = bcadd($this->store[$key]??0, $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'in'; $model->title = $this->getTitle($category, $amount); @@ -129,7 +129,7 @@ class CapitalFlowLogic extends BaseLogic * @param $mark * @return mixed */ - public function storeExpense($category, $linkType, $linkId, $amount, $mark = '') + public function storeExpense($category, $linkType, $linkId, $amount, $mark = '',$key='') { $model = new CapitalFlow(); $model->store_id = $this->store['store_id']; @@ -138,8 +138,8 @@ class CapitalFlowLogic extends BaseLogic $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; - $model->before_balance = $this->store['balance']; - $model->balance = bcsub($this->store['balance'], $amount, 2); + $model->before_balance = $this->store[$key]??0; + $model->balance = bcsub($this->store[$key], $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'out'; $model->title = $this->getTitle($category, $amount); @@ -166,6 +166,7 @@ class CapitalFlowLogic extends BaseLogic case 'store_order_refund': return "店铺订单退款{$amount}元"; case 'store_margin_refund': + case 'store_paid_deposit_refund': return "店铺退还保证金{$amount}元"; case 'user_order_promotion': return "订单推广佣金{$amount}元"; @@ -181,6 +182,12 @@ class CapitalFlowLogic extends BaseLogic return "用户减少{$amount}元"; case 'user_withdrawal': return "用户提现{$amount}元"; + case 'now_money_refund': + return "订单退回到余额{$amount}元"; + case 'purchase_refund': + return "订单退回到采购款{$amount}元"; + case 'store_paid_deposit_add': + return "门店增加保证金{$amount}元"; default: return "订单支付{$amount}元"; } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 71dcbd310..68d2e52cb 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -7,7 +7,9 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\user\User; use PDO; +use support\Log; /** * 产品佣金计算 @@ -21,20 +23,26 @@ class CommissionProductLogic extends BaseLogic */ function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0) { - $product = StoreBranchProduct::where('id', $find['product_id'])->where('store_id', $order['store_id'])->find(); - if (!$product) { - $product = StoreProduct::where('id', $find['product_id'])->find(); - } + $product = StoreProduct::where('id', $find['product_id'])->find(); if ($product) { - if ($user_ship == 5) { - $top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); - if ($top_cate_id == 15189) { - $this->b($find, $order, $product); - return true; - } + if ($product['product_type'] == 4) { + $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; } else { - $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + if ($user_ship == 5) { + $top_cate_id = $product['top_cate_id']; + if ($top_cate_id == 15189) { + $this->b($find, $order, $product, $user_ship); + return true; + } + } elseif ($user_ship == 0) { + $this->b($find, $order, $product, $user_ship); + return true; + } else { + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + } } + return true; } } @@ -44,82 +52,273 @@ class CommissionProductLogic extends BaseLogic */ public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { - // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['price'], $find['cart_num']); - // $Distribution = Distribution::where('rate', $rose)->find(); - //门店 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'number' => bcmul($total_price, 0.05, 2), - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - //平台 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'number' => bcmul($total_price, 0.02, 2), - 'oid' => $order['id'], - 'type' => 2, - 'status' => 1, - ]; - //村长 - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $village_uid, - 'number' => bcmul($total_price, 0.01, 2), - 'oid' => $order['id'], - 'type' => 3, - 'status' => 1, - ]; + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['purchase']; + + $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($purchase_price, 0.02, 2); //平台 + $attrition_number = bcmul($purchase_price, 0.01, 2); //损耗 + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + $number4 = bcadd($attrition_number, $number2, 2); + + //会员 + $uid = 0; + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } + if ($order['uid'] > 0) { + $uid = $order['uid']; + } + $user = User::where('id', $uid)->find(); + $delete_time=null; + $nickname='会员'; + if ($user) { + $moeny = bcsub($user['total_recharge_amount'], $user['purchase_funds'], 2); + if ($moeny < $user['first_purchase_funds']) { + $delete_time=1; + $nickname='首充没用完,会员不分配'; + } + } + if (in_array($user_ship, [2, 3])) { + $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'price' => $price, + 'other_uid' => $uid, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } else { + $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $uid, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.07, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, $number4, 2); + } + //队长 $data[] = [ + 'nickname' => '零售队长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], - 'other_uid' => $brigade_uid, - 'number' => bcmul($total_price, 0.01, 2), + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $brigade_number, 'oid' => $order['id'], 'type' => 4, 'status' => 1, + 'is_activity' => 1, ]; - //会员 - if ($user_ship == 1) { - $uid = $order['spread_uid']; - } else { - $uid = 0; - } - // $data[] = [ - // 'store_id' => $order['store_id'], - // 'product_id' => $find['product_id'], - // 'other_uid' => $uid, - // 'number' => bcmul($total_price, $Distribution['user'], 2), - // 'oid' => $order['id'], - // 'type' => 0, - // 'status' => 1, - // ]; - - //个人店铺 - if ($order['spread_uid'] > 0) { - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $order['spread_uid'], - 'number' => bcmul($total_price, 0.07, 2), - 'oid' => $order['id'], - 'type' => 5, - 'status' => 1, - ]; - } + //村长 $data[] = [ + 'nickname' => '零售村长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, - 'number' => bcmul($total_price, 0.01, 2), + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 1, + ]; + //门店 + $data[] = [ + 'nickname' => '零售门店', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + $data[] = [ + 'nickname' => '零售平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => 1, + ]; + + $data[] = [ + 'nickname' => '零售消耗', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, + 'number' => $attrition_number, + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + ]; + + + (new StoreFinanceFlowProduct())->saveAll($data); + } + + /** + * 商户价结算 + */ + public function b($find, $order, $product, $user_ship) + { + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['purchase']; + + $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($purchase_price, 0.02, 2); //平台 + $attrition_number = bcmul($purchase_price, 0.01, 2); //损耗 + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + $number4 = bcadd($attrition_number, $number2, 2); + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, $number4, 2); + } + + //队长 + $data[] = [ + 'nickname' => '商户价队长预留', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => 1, + ]; + //村长 + $data[] = [ + 'nickname' => '商户价村长预留', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 1, + ]; + //门店 + $data[] = [ + 'nickname' => '商户价门店', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + $data[] = [ + 'nickname' => '商户价平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => 1, + ]; + + $data[] = [ + 'nickname' => '商户价消耗', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, + 'number' => $attrition_number, 'oid' => $order['id'], 'type' => 6, 'status' => 1, @@ -127,32 +326,93 @@ class CommissionProductLogic extends BaseLogic (new StoreFinanceFlowProduct())->saveAll($data); } - /** - * 商户价结算 - */ - public function b($find, $order, $product) + //活动商品结算 + public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $price = $product['price']; + $brigade_number = bcmul($total_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($total_price, 0.02, 2); //平台 + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, $number2, 2); + } + + //队长 + $data[] = [ + 'nickname' => '活动队长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $brigade_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => 1, + ]; + //村长 + $data[] = [ + 'nickname' => '活动村长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $village_uid, + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 1, + ]; //门店 $data[] = [ + 'nickname' => '活动门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, - 'number' => bcmul($total_price, 0.05, 2), + 'price' => $price, + 'total_price' => $store_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0, + 'number' => $store_number, 'oid' => $order['id'], 'type' => 1, 'status' => 1, + 'is_activity' => 1, ]; //平台 $data[] = [ + 'nickname' => '活动平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, - 'number' => bcmul($total_price, 0.02, 2), + 'price' => $price, + 'total_price' => $platform_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, 'oid' => $order['id'], 'type' => 2, 'status' => 1, + 'is_activity' => 1, ]; (new StoreFinanceFlowProduct())->saveAll($data); } diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index 79c823916..d3da5fd75 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order = $order; $financeLogic->user['uid'] = $order['uid']; - $pay_price = $order['pay_price']; + $pay_price=bcsub($order['pay_price'],$order['refund_price'],2); $number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number'); $fees = bcsub($pay_price, $number, 2); if ($fees > 0) { @@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic $financeLogic->user['uid'] = $order['uid']; $financeLogic->other_arr['vip_uid'] = $uid; $financeLogic->order = $order; - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 45122cc5c..0092c9410 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -2,6 +2,7 @@ namespace app\common\logic; +use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\user_ship\UserShipLogic; use app\api\logic\order\OrderLogic; use app\common\enum\OrderEnum; @@ -30,6 +31,7 @@ use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; use app\common\service\PushService; +use support\exception\BusinessException; use support\Log; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -52,7 +54,7 @@ class PayNotifyLogic extends BaseLogic } catch (\Exception $e) { Db::rollback(); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); - throw new \Exception($e->getMessage()); + throw new BusinessException($e->getMessage()); } } @@ -70,13 +72,14 @@ class PayNotifyLogic extends BaseLogic $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); $user = User::where('id', $order['uid'])->find(); if ($user['now_money'] < $order['pay_price']) { - throw new \Exception('余额不足'); + throw new BusinessException('余额不足'); } // $order->money = $order['pay_price']; $order->paid = 1; + $order->status = 1; $order->pay_time = time(); if (!$order->save()) { - throw new \Exception('订单保存出错'); + throw new BusinessException('订单保存出错'); } if ($order['is_storage'] == 1) { $order->status = 2; @@ -95,7 +98,7 @@ class PayNotifyLogic extends BaseLogic // self::addUserSing($order); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 3, $order['store_id']); - self::dealProductLog($order); + // self::dealProductLog($order); self::afterPay($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { @@ -105,14 +108,14 @@ class PayNotifyLogic extends BaseLogic ]; self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); } - if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } if (in_array($order['shipping_type'], [1, 2])) { PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } @@ -161,7 +164,7 @@ class PayNotifyLogic extends BaseLogic ]; UserSign::create($sing); - self::dealProductLog($order); + // self::dealProductLog($order); } @@ -183,6 +186,7 @@ class PayNotifyLogic extends BaseLogic } $order->money = $order['pay_price']; $order->paid = 1; + $order->status = 1; $order->pay_time = time(); if (!$order->save()) { throw new \Exception('订单保存出错'); @@ -192,8 +196,7 @@ class PayNotifyLogic extends BaseLogic UserProductStorageLogic::add($order); } // 减去采购款 - $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); + User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']); @@ -202,15 +205,15 @@ class PayNotifyLogic extends BaseLogic // } // self::addUserSing($order); self::afterPay($order); - if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } - self::dealProductLog($order); + // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } + // self::dealProductLog($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { $checkArr = [ 'cart_id' => $order['cart_id'], @@ -252,7 +255,7 @@ class PayNotifyLogic extends BaseLogic } $user = User::where('id', $order['uid'])->find(); if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 - $order->status = 2; + // $order->status = 2; } else { $capitalFlowDao = new CapitalFlowLogic($user); //微信支付和用户余额无关 @@ -268,7 +271,7 @@ class PayNotifyLogic extends BaseLogic } self::afterPay($order, $extra['transaction_id']); // self::addUserSing($order); - self::dealProductLog($order); + // 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]); @@ -323,34 +326,10 @@ class PayNotifyLogic extends BaseLogic //订单购物详情 StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); - + self::balance_purchase_refund($order); //处理财务流水退还 (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); - 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(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $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(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $order['pay_price']); - } - UserSignLogic::RefundOrder($order); - return true; - } //积分 UserSignLogic::RefundOrder($order); //微信日志 user_order_refund @@ -361,6 +340,48 @@ class PayNotifyLogic extends BaseLogic return true; } + /** + * 余额采购款退款 + */ + public static function balance_purchase_refund($order, $type = 1, $money = 0) + { + 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(); + $capitalFlowDao = new CapitalFlowLogic($user); + if ($type == 1) { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0); + $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); + StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]); + } else { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0); + $user->now_money = bcadd($user['now_money'], $money, 2); + } + $user->save(); + //增加数量 + self::addStock($order['id']); + } + if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 + $user = User::where('id', $order['uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + if ($type == 1) { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); + $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); + StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]); + } else { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1); + $user->purchase_funds = bcadd($user['purchase_funds'], $money, 2); + } + $user->save(); + //增加数量 + self::addStock($order['id']); + } + UserSignLogic::RefundOrder($order); + + return true; + } + } + /** * 现金退款相关 * @param $orderSn @@ -487,7 +508,8 @@ class PayNotifyLogic extends BaseLogic } $order->paid = 1; $order->pay_time = time(); - $order->status = 2; + $order->status = 1; + // $order->status = 2; if ($order['reservation'] == 1) { $order->status = 1; } @@ -500,16 +522,16 @@ class PayNotifyLogic extends BaseLogic } $cashFlowLogic = new CashFlowLogic(); $cashFlowLogic->insert($order['store_id'], $order['pay_price']); - self::dealProductLog($order); + // self::dealProductLog($order); - if ($order && $order['store_id'] && $order['reservation'] != 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order && $order['store_id'] && $order['reservation'] != 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } // Redis::send('push-platform-print', ['id' => $order['id']]); @@ -544,7 +566,7 @@ class PayNotifyLogic extends BaseLogic } $order->save(); self::afterPay($order); - self::dealProductLog($order); + // self::dealProductLog($order); // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; @@ -554,14 +576,14 @@ class PayNotifyLogic extends BaseLogic // 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); - } + // 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; } @@ -574,20 +596,39 @@ class PayNotifyLogic extends BaseLogic { StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); - foreach ($arr as $k => $v) { - $branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); - if($branchProduct){ - $stock=bcsub($branchProduct['stock'],$v['cart_num'],2); - StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2), - 'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]); - } - $storeProduct=StoreProduct::where('id', $v['product_id'])->find(); - if($storeProduct){ - $stock=bcsub($storeProduct['stock'],$v['cart_num'],2); - StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), - 'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]); + try { + foreach ($arr as $k => $v) { + $branchProduct = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $v['store_id'])->find(); + $storeProduct = StoreProduct::where('id', $v['product_id'])->find(); + + if ($branchProduct) { + $stock = bcsub($branchProduct['stock'], $v['cart_num'], 2); + StoreBranchProduct::update([ + 'stock' => $stock, + 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), + 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2) + ], ['id' => $branchProduct['id']]); + } else { + StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct); + StoreBranchProduct::update([ + 'stock' => -$v['cart_num'], + 'sales' => $v['cart_num'] + ], ['product_id' => $v['product_id'],'store_id'=>$v['store_id']]); + } + if ($storeProduct) { + $stock = bcsub($storeProduct['stock'], $v['cart_num'], 2); + StoreProduct::update([ + 'stock' => $stock, + 'total_price' => bcmul($stock, $storeProduct['purchase'], 2), + 'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2) + ], ['id' => $v['product_id']]); + } } + } catch (\Throwable $e) { + Log::error('订单库存更新失败:' . $e->getMessage()); + // 异常处理代码,例如记录日志或发送通知等。 } + $financeLogic = new StoreFinanceFlowLogic(); $off_activity = Config::where('name', 'off_activity')->value('value'); $village_uid = 0; @@ -623,108 +664,35 @@ class PayNotifyLogic extends BaseLogic return false; } - //如果是会员需要返回会员金额 - // if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) { - // $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']); - // } - if ($order['spread_uid'] > 0 || $user_ship > 0) { - if ($order['spread_uid'] > 0 && $user_ship == 0) { - $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); - if ($user_ship == 2) { - $village_uid = $order['spread_uid']; - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } - } - } elseif ($user_ship == 3) { - $brigade_uid = $order['spread_uid']; - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - } - } 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'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } - } + if ($order['uid'] > 0) { + $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); + if ($address) { + $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); + if ($arr1) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; } - } else { - //查询用户对应的村长和队长 - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; } } - 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); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - } catch (\Exception $e) { - Log::error('活动分润报错' . $e->getMessage()); - return false; - } - } - switch ($user_ship) { - case 1: // 厨师 - //case 4: // 商户 - //case 5: // 种养殖 - // case 6: // 酒店 - // case 7: // 食堂 - case 8: // 一条龙 - CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id); - break; - case 2: // 村长 - CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id); - break; - case 3: // 队长 - CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id); - break; - default: - CommissionLogic::setStore($order, $transaction_id); - break; - } - } else { - 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); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - } catch (\Exception $e) { - Log::error('活动分润报错' . $e->getMessage()); - return false; - } - } - CommissionLogic::setStore($order, $transaction_id); } + if ($order['spread_uid'] > 0) { + $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); + } + + 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); + } + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + } catch (\Throwable $e) { + Log::error('分润报错' . $e->getMessage()); + return false; + } + return true; } /** diff --git a/app/common/logic/PaymentLogic.php b/app/common/logic/PaymentLogic.php index 322cc442d..433c6a625 100644 --- a/app/common/logic/PaymentLogic.php +++ b/app/common/logic/PaymentLogic.php @@ -8,7 +8,9 @@ use app\common\enum\PayEnum; use app\common\model\user\UserAuth; use app\common\service\pay\PayService; use Exception; +use support\exception\BusinessException; use support\Log; +use Throwable; use function DI\string; @@ -40,34 +42,33 @@ class PaymentLogic extends BaseLogic return ['pay_way' => PayEnum::BALANCE_PAY]; } try { - if(isset($order['price'])){ - $order['pay_price'] = $order['price']; - } - switch ($payWay) { - case PayEnum::WECHAT_PAY_MINI: - $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); - $order = [ - 'out_trade_no' => $paySn, - 'description' => '商品', - 'amount' => [ - 'total' => intval($order['pay_price'] * 100), - 'currency' => 'CNY', - ], - "payer" => [ - "openid" => $auth['openid'] - ], - 'attach' => $from - ]; - $wechat = new PayService(1); - $result = $wechat->wechat->mini($order)->toArray(); - break; - default: - self::$error = '订单异常'; - $result = false; - } - } catch (Exception $e) { - \support\Log::info($e->extra['message']?? $e->getMessage()); - throw new \Exception($e->extra['message']?? $e->getMessage()); + if (isset($order['price'])) { + $order['pay_price'] = $order['price']; + } + switch ($payWay) { + case PayEnum::WECHAT_PAY_MINI: + $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); + $order = [ + 'out_trade_no' => $paySn, + 'description' => '商品', + 'amount' => [ + 'total' => intval($order['pay_price'] * 100), + 'currency' => 'CNY', + ], + "payer" => [ + "openid" => $auth['openid'] + ], + 'attach' => $from + ]; + $wechat = new PayService(1); + $result = $wechat->wechat->mini($order)->toArray(); + break; + default: + throw new BusinessException('支付方式异常'); + } + } catch (Throwable $e) { + Log::info($e->extra['message'] ?? $e->getMessage()); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } return $result; } @@ -75,13 +76,12 @@ class PaymentLogic extends BaseLogic /** * 微信条码支付 */ - public static function codepay($auth_code, $order,$description='条码商品') + public static function codepay($auth_code, $order, $description = '条码商品') { $pattern = '/^(10|11|12|13|14|15)\d{16}$/'; if (!preg_match($pattern, (string)$auth_code)) { - self::$error = '请使用正确的微信收付款条码'; - return false; + throw new BusinessException('请使用正确的微信收付款条码'); } $data = [ 'description' => $description, @@ -94,26 +94,25 @@ class PaymentLogic extends BaseLogic ], 'scene_info' => [ "store_info" => [ - 'id' => (string)$order['store_id']??1 + 'id' => (string)$order['store_id'] ?? 1 ] ], - 'attach'=>'wechat_common' + 'attach' => 'wechat_common' ]; - if(isset($order['attach']) && $order['attach']!=''){ + if (isset($order['attach']) && $order['attach'] != '') { $data['attach'] = $order['attach']; } $wechat = new PayService(1); try { $result = $wechat->wechat->pos($data)->toArray(); - } catch (Exception $e) { - Log::error('条码支付报错',['message' => $e->extra['message']?? $e->getMessage(),'code'=>$e->getCode()]); + } catch (Throwable $e) { + Log::error('条码支付报错', ['message' => $e->extra['message'] ?? $e->getMessage(), 'code' => $e->getCode()]); if (getenv('APP_DEBUG') == true) { - self::$error = $e->extra['message'] ?? $e->getMessage(); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } else { - self::$error = $e->getMessage(); + throw new BusinessException($e->getMessage()); } - return false; } return $result; } @@ -126,26 +125,24 @@ class PaymentLogic extends BaseLogic $pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/'; if (!preg_match($pattern, (string)$auth_code)) { - self::$error = '请使用正确的支付宝收付款条码'; - return false; + throw new BusinessException('请使用正确的支付宝收付款条码'); } $order = [ 'subject' => '条码商品', 'out_trade_no' => (string)$order['order_id'], 'auth_code' => (string)$auth_code, 'total_amount' => $order['pay_price'], - 'extend_params'=>['attach'=>'alipay_cashier'] + 'extend_params' => ['attach' => 'alipay_cashier'] ]; $wechat = new PayService(); try { $result = $wechat->alipay->pos($order)->toArray(); - } catch (Exception $e) { + } catch (Throwable $e) { if (getenv('APP_DEBUG') == true) { - self::$error = $e->extra['message'] ?? $e->getMessage(); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } else { - self::$error = $e->getMessage(); + throw new BusinessException($e->getMessage()); } - return false; } return $result; } diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 7fd7b23da..98b3131be 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -151,18 +151,18 @@ class StoreFinanceFlowLogic extends BaseLogic $store = SystemStore::where('id', $store_id)->find(); $capitalFlowDao = new CapitalFlowLogic($store, 'store'); if ($money > 0) { - $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money); + $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); } if ($deposit > 0) { - $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit); + $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit,'','paid_deposit'); SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); } $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find(); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]); if ($find) { if ($find['number'] > 0) { - $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number']); + $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number'],'','attrition'); SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); } } @@ -183,39 +183,40 @@ class StoreFinanceFlowLogic extends BaseLogic ->select(); foreach ($list as $k => $value) { //用户 - switch ($value['type']) { - case 0: - if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { - $user = User::where('id', $value['other_uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->now_money = bcsub($user['now_money'], $value['number'], 2); - $user->save(); - // Log::error('aa'.$a); - // Log::error('aa'.$user['now_money']); - // Log::error('aa'.$value['number']); - $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); - } - break; - //商户 - case 1: - $store = SystemStore::where('id', $store_id)->find(); - $capitalFlowDao = new CapitalFlowLogic($store, 'store'); - if ($value['number'] > 0 && $value['financial_type'] == 2) { - SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update(); - $capitalFlowDao->storeExpense('store_paid_deposit_dec', 'order', $value['order_id'],$value['number']); + if($value['type']==0){ + if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { + $user = User::where('id', $value['other_uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + $user->now_money = bcsub($user['now_money'], $value['number'], 2); + $user->save(); + $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); + } + }elseif($value['type']==1){ + $store = SystemStore::where('id', $store_id)->find(); + $capitalFlowDao = new CapitalFlowLogic($store, 'store'); + if ($value['number'] > 0 && $value['financial_type'] == 2) { + $find=SystemStore::where('id', $value['store_id'])->find(); + $find->store_money=bcsub($find['store_money'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_money_refund', 'order', $value['order_id'],$value['number'],'','store_money'); - } - if ($value['number'] > 0 && $value['financial_type'] == 16) { - SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update(); - $capitalFlowDao->storeExpense('store_attrition_dec', 'order', $value['order_id'], $value['number']); + } + if ($value['number'] > 0 && $value['financial_type'] == 16) { + $find=SystemStore::where('id', $value['store_id'])->find(); + $find->attrition=bcsub($find['attrition'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_attrition_refund', 'order', $value['order_id'], $value['number'],'','attrition'); - } - break; + } } } $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find(); if ($find && $find['number'] > 0) { - SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update(); + $find=SystemStore::where('id', $value['store_id'])->find(); + $capitalFlowDao = new CapitalFlowLogic($find, 'store'); + $find->paid_deposit=bcsub($find['paid_deposit'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_paid_deposit_refund', 'order', $value['order_id'],$value['number'],'','paid_deposit'); } // $data = StoreFinanceFlow::where('order_sn', $orderSn)->select(); // foreach ($data as $k => &$value) { diff --git a/app/common/logic/UserSignLogic.php b/app/common/logic/UserSignLogic.php index 47cfc609b..7e0d443cf 100644 --- a/app/common/logic/UserSignLogic.php +++ b/app/common/logic/UserSignLogic.php @@ -67,7 +67,7 @@ class UserSignLogic extends BaseLogic $write = self::write($order, $total_vip, 0, 1, 9); self::write_log($write, $total_vip, 0, 7); self::write_log($write, $total_vip, 0, 9, 0); - User::where('id', $order->uid)->inc('integral', $total_vip)->update(); + User::where('id', $order->uid)->update(['integral'=>$total_vip,'first_purchase_funds'=>$order['price']]); } return true; } diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 53e5d26fd..a67acfad3 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -21,6 +21,7 @@ use Exception; use support\Cache; use think\facade\Db; use app\common\model\system_store\SystemStore; +use support\exception\BusinessException; class StoreOrderLogic extends BaseLogic { @@ -46,8 +47,7 @@ class StoreOrderLogic extends BaseLogic $where = ['is_pay' => 0]; $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } try { self::$total_price = 0; @@ -164,8 +164,7 @@ class StoreOrderLogic extends BaseLogic } } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } return ['order' => $order, 'cart_list' => $cart_select]; } @@ -222,8 +221,8 @@ class StoreOrderLogic extends BaseLogic return $order; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -238,7 +237,7 @@ class StoreOrderLogic extends BaseLogic $query->field(['id', 'oid', 'product_id', 'cart_info']); }])->where($params)->find(); if (empty($order)) { - throw new \Exception('订单不存在'); + throw new BusinessException('订单不存在'); } $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; @@ -251,12 +250,31 @@ class StoreOrderLogic extends BaseLogic if ($order['pay_type'] == 19){ $order['deduction_price'] = "0.00"; } - - $detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray(); + $product=StoreOrderCartInfo::where(['oid'=>$order['id']]) + ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time') + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); + if($find){ + $item['image']=$find['image'];//商品图片 + $item['name']=$find['store_name'];//商品名称 + $item['store_info']=$find['store_info'];//商品规格 + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; + }else{ + $item['image']='';//商品图片 + $item['unit_name']='';//商品图片 + $item['cate_name']='';//商品图片 + $item['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['nickname']=''; + $item['system_store']=''; + $item['cart_info']=[]; + } + return $item; //返回处理后的数据。 + }); + $order['product']=$product; $vip =0; - if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){ - $vip = 1; - } $order['vip'] = $vip; return $order->toArray(); } @@ -372,7 +390,7 @@ class StoreOrderLogic extends BaseLogic return false; } catch (Exception $e) { \support\Log::info($e->extra['message'] ?? $e->getMessage()); - throw new \Exception($e->extra['message'] ?? $e->getMessage()); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } } @@ -383,7 +401,7 @@ class StoreOrderLogic extends BaseLogic $code = generateRandomCode(); $phone = User::where('id',$param['uid'])->value('mobile'); if(empty($phone)){ - throw new \Exception('用户未设置手机号'); + throw new BusinessException('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code); @@ -413,8 +431,7 @@ class StoreOrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $params['cart_id']) ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } $newArr = []; //检查购物车对比店铺得商品数量差异 diff --git a/app/common/logic/user_product_storage/UserProductStorageLogic.php b/app/common/logic/user_product_storage/UserProductStorageLogic.php index f9e2af9fe..efe212f6b 100644 --- a/app/common/logic/user_product_storage/UserProductStorageLogic.php +++ b/app/common/logic/user_product_storage/UserProductStorageLogic.php @@ -9,6 +9,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\user\User; use app\common\model\user_product_storage\UserProductStorage; use app\common\model\user_product_storage_log\UserProductStorageLog; +use support\exception\BusinessException; use think\facade\Db; /** @@ -54,9 +55,7 @@ class UserProductStorageLogic extends BaseLogic $find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find(); if($find){ if($find['nums']<$v['nums']){ - self::setError('库存不足'); - Db::commit(); - return false; + throw new BusinessException("库存不足"); } $nums=bcsub($find['nums'],$v['nums']); $find->nums=$nums; @@ -86,17 +85,14 @@ class UserProductStorageLogic extends BaseLogic $data_log[$k]['times']=$times; $data_log[$k]['status']=$status; }else{ - self::setError('没有查询到该商品'); - Db::commit(); - return false; + throw new BusinessException("没有查询到该商品"); } } (new UserProductStorageLog())->saveAll($data_log); Db::commit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } \ No newline at end of file diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index 124eb2233..ae0ad6b83 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -7,8 +7,9 @@ use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店商品属性值辅助表模型 @@ -36,10 +37,17 @@ class StoreBranchProduct extends BaseModel } - public function store() { return $this->hasOne(StoreProduct::class,'id','product_id'); } - + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'branch_product','更新前'); + channelLog($data->toArray(),'branch_product','更新后'); + }catch(Throwable $e){ + Log::error('branch_product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/store_finance_flow/StoreFinanceFlow.php b/app/common/model/store_finance_flow/StoreFinanceFlow.php index c3d449622..38f79b90c 100644 --- a/app/common/model/store_finance_flow/StoreFinanceFlow.php +++ b/app/common/model/store_finance_flow/StoreFinanceFlow.php @@ -7,8 +7,9 @@ use app\common\model\BaseModel; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店流水模型 @@ -36,4 +37,12 @@ class StoreFinanceFlow extends BaseModel return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); } + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_finance_flow','更新前'); + channelLog($data->toArray(),'store_finance_flow','更新后'); + }catch(Throwable $e){ + Log::error('store_finance_flow:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php index f371f35ba..bea36cb01 100644 --- a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php +++ b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php @@ -4,8 +4,9 @@ namespace app\common\model\store_finance_flow_product; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 财务流水商品明细 @@ -17,4 +18,13 @@ class StoreFinanceFlowProduct extends BaseModel use SoftDelete; protected $name = 'store_finance_flow_product'; protected $deleteTime = 'delete_time'; + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_finance_flow_product','更新前'); + channelLog($data->toArray(),'store_finance_flow_product','更新后'); + }catch(Throwable $e){ + Log::error('store_finance_flow_product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 57a005122..815958362 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -9,8 +9,9 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; +use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 订单列表模型 @@ -99,4 +100,13 @@ class StoreOrder extends BaseModel })->field("FROM_UNIXTIME(create_time,'$timeType') as days,$str as num") ->group('days')->select()->toArray(); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_order','更新前'); + channelLog($data->toArray(),'store_order','更新后'); + }catch(Throwable $e){ + Log::error('store_order:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php index 2939ba149..93b2b3518 100644 --- a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php +++ b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php @@ -4,7 +4,9 @@ namespace app\common\model\store_order_cart_info; use app\common\model\BaseModel; use app\common\model\store_branch_product\StoreBranchProduct; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; +use Throwable; class StoreOrderCartInfo extends BaseModel { @@ -18,4 +20,13 @@ class StoreOrderCartInfo extends BaseModel { return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_order_cart_info','更新前'); + channelLog($data->toArray(),'store_order_cart_info','更新后'); + }catch(Throwable $e){ + Log::error('store_order_cart_info:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index dc810fdda..ddcfe97e9 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -6,8 +6,9 @@ namespace app\common\model\store_product; use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_unit\StoreProductUnit; +use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 商品列表模型 @@ -31,8 +32,14 @@ class StoreProduct extends BaseModel { return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); - } - + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'product','更新前'); + channelLog($data->toArray(),'product','更新后'); + }catch(Throwable $e){ + Log::error('product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php index ac1c4345b..ff209e545 100644 --- a/app/common/model/system_store/SystemStore.php +++ b/app/common/model/system_store/SystemStore.php @@ -4,8 +4,9 @@ namespace app\common\model\system_store; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店列表模型 @@ -18,5 +19,12 @@ class SystemStore extends BaseModel protected $name = 'system_store'; protected $deleteTime = 'delete_time'; - + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'system_store','更新前'); + channelLog($data->toArray(),'system_store','更新后'); + }catch(Throwable $e){ + Log::error('system_store:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/system_store/SystemStoreMenu.php b/app/common/model/system_store/SystemStoreMenu.php index 827a7a273..d1ecfcc07 100644 --- a/app/common/model/system_store/SystemStoreMenu.php +++ b/app/common/model/system_store/SystemStoreMenu.php @@ -16,6 +16,7 @@ namespace app\common\model\system_store; use app\common\model\BaseModel; +use think\model\concern\SoftDelete; /** @@ -25,7 +26,8 @@ use app\common\model\BaseModel; */ class SystemStoreMenu extends BaseModel { - + use SoftDelete; + protected $deleteTime = 'delete_time'; } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index e0ae912f4..704b7ed2a 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -9,7 +9,9 @@ use app\common\model\BaseModel; use app\common\model\user_label\UserLabel; use app\common\model\user_ship\UserShip; use app\common\service\FileService; +use support\Log; use think\model\concern\SoftDelete; +use Throwable; /** * 用户模型 @@ -25,15 +27,14 @@ class User extends BaseModel //会员类型 public function userShip() { - return $this->hasOne(UserShip::class,'id','user_ship') - ->bind(['vip_name'=>'title','discount','limit']); + return $this->hasOne(UserShip::class, 'id', 'user_ship') + ->bind(['vip_name' => 'title', 'discount', 'limit']); } public function userLabel() { - return $this->hasOne(UserLabel::class,'label_id','label_id') + return $this->hasOne(UserLabel::class, 'label_id', 'label_id') ->bind(['label_name']); - } /** @@ -184,15 +185,24 @@ class User extends BaseModel * @param $timeType * @return mixed */ - public function getTrendData($time, $where, $timeType,$create_time='create_time') + public function getTrendData($time, $where, $timeType, $create_time = 'create_time') { - return $this->where($where)->where(function ($query) use ($time,$create_time) { + return $this->where($where)->where(function ($query) use ($time, $create_time) { if ($time[0] == $time[1]) { - $query->whereDay($create_time, date('Y-m-d',$time[0])); + $query->whereDay($create_time, date('Y-m-d', $time[0])); } else { $time[1] = $time[1] + 86400; $query->whereTime($create_time, 'between', $time); } })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'user','更新前'); + channelLog($data->toArray(),'user','更新后'); + }catch(Throwable $e){ + Log::error('user:'.$e->getMessage()); + } + } } diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 5f8abf079..24e61c73e 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -4,8 +4,9 @@ namespace app\common\model\warehouse_product; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 商品仓储信息模型 @@ -18,5 +19,12 @@ class WarehouseProduct extends BaseModel protected $name = 'warehouse_product'; protected $deleteTime = 'delete_time'; - + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'warehouse_product','更新前'); + channelLog($data->toArray(),'warehouse_product','更新后'); + }catch(Throwable $e){ + Log::error('warehouse_product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 074aa2d02..9d86d6924 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -4,8 +4,9 @@ namespace app\common\model\warehouse_product_storege; use app\common\model\BaseModel; +use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 仓库商品存储 @@ -17,6 +18,13 @@ class WarehouseProductStorege extends BaseModel use SoftDelete; protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; - - -} \ No newline at end of file + public static function onAfterWrite($data) + { + try { + channelLog($data->getOrigin(), 'warehouse_product_storege', '更新前'); + channelLog($data->toArray(), 'warehouse_product_storege', '更新后'); + } catch (Throwable $e) { + Log::error('warehouse_product_storege:' . $e->getMessage()); + } + } +} diff --git a/app/common/service/generator/stub/php/logic.stub b/app/common/service/generator/stub/php/logic.stub index e7ad55245..901e5232d 100644 --- a/app/common/service/generator/stub/php/logic.stub +++ b/app/common/service/generator/stub/php/logic.stub @@ -5,6 +5,7 @@ {USE} use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -34,10 +35,9 @@ class {UPPER_CAMEL_NAME}Logic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -59,10 +59,9 @@ class {UPPER_CAMEL_NAME}Logic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/common/service/wechat/WeChatMnpService.php b/app/common/service/wechat/WeChatMnpService.php index c9cb5ef25..e298eaa6f 100644 --- a/app/common/service/wechat/WeChatMnpService.php +++ b/app/common/service/wechat/WeChatMnpService.php @@ -109,9 +109,9 @@ class WeChatMnpService $dateTime = new DateTime(date('Y-m-d H:i:s')); $formattedDateTime = $dateTime->format('Y-m-d\TH:i:s.uP'); if(in_array($logistics_type,[1,2,4])){ - $item_desc='商品'; + $item_desc='门店商品'; }else{ - $item_desc='充值'; + $item_desc='采购礼包'; } return $this->app->getClient()->postJson("wxa/sec/order/upload_shipping_info?access_token=$token", [ 'order_key' =>[ diff --git a/app/common/service/xlsx/OrderDetail.php b/app/common/service/xlsx/OrderDetail.php index 84ba39e80..2fa5e115d 100644 --- a/app/common/service/xlsx/OrderDetail.php +++ b/app/common/service/xlsx/OrderDetail.php @@ -106,13 +106,17 @@ class OrderDetail $sheet->mergeCells('A' . ($count + 11) . ':J' . $count + 11); - $sheet->setCellValue('A' . $count + 12, '仓库',); - // $sheet->setCellValue('B' . $count + 11, $this->warehouse); + + $sheet->setCellValue('A' . $count + 12, '下单人',); $sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12); - $sheet->setCellValue('D' . $count + 12, '送货'); - $sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12); - $sheet->setCellValue('G' . $count + 12, '签收人'); - $sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12); + $sheet->setCellValue('D' . $count + 12, '电话'); + + $sheet->setCellValue('A' . $count + 13, '仓库',); + $sheet->mergeCells('B' . ($count + 13) . ':C' . $count + 13); + $sheet->setCellValue('D' . $count + 13, '送货'); + $sheet->mergeCells('E' . ($count + 13) . ':F' . $count + 13); + $sheet->setCellValue('G' . $count + 13, '签收人'); + $sheet->mergeCells('H' . ($count + 13) . ':J' . $count + 13); // 设置单元格的样式 $styleArray = [ @@ -131,7 +135,7 @@ class OrderDetail ], ], ]; - $sheet->getStyle('A1:J' . ($count + 12))->applyFromArray($styleArray); + $sheet->getStyle('A1:J' . ($count + 13))->applyFromArray($styleArray); // 保存文件到 public 下 diff --git a/app/common/validate/BaseValidate.php b/app/common/validate/BaseValidate.php index 92bf44e7a..e5c1fd36b 100644 --- a/app/common/validate/BaseValidate.php +++ b/app/common/validate/BaseValidate.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace app\common\validate; use app\common\service\JsonService; +use support\exception\BusinessException; use taoser\Validate; class BaseValidate extends Validate @@ -31,7 +32,7 @@ class BaseValidate extends Validate public function post() { if (!(request()->method() == 'POST')) { - JsonService::throw('请求方式错误,请使用post请求方式'); + throw new BusinessException('请求方式错误,请使用post请求方式'); } $this->method = 'POST'; return $this; @@ -45,7 +46,7 @@ class BaseValidate extends Validate public function get() { if (!(request()->method() == 'GET')) { - JsonService::throw('请求方式错误,请使用get请求方式'); + throw new BusinessException('请求方式错误,请使用get请求方式'); } return $this; } @@ -79,7 +80,7 @@ class BaseValidate extends Validate if (!$result) { $exception = is_array($this->error) ? implode(';', $this->error) : $this->error; - JsonService::throw($exception); + throw new BusinessException($exception); } // 3.成功返回数据 return $params; diff --git a/app/functions.php b/app/functions.php index e2b128000..d3275a116 100644 --- a/app/functions.php +++ b/app/functions.php @@ -5,7 +5,7 @@ */ use app\common\service\FileService; - +use support\Log; if (!function_exists('substr_symbol_behind')) { /** @@ -500,3 +500,26 @@ if (!function_exists('convertNumber')) { } } } + +/** + * 日志记录 + * @param product + * @param branch_product + * @param product_storege + */ +function onBeforeUpdate($data, $type) +{ + $log = Log::channel($type); + $log->info('更新前:',$data); +} +function onAfterUpdate($data, $type) +{ + $log = Log::channel($type); + $log->info('更新后:' ,$data); +} + +function channelLog($data, $type,$title='更新前') +{ + $log = Log::channel($type); + $log->info($title ,$data); +} \ No newline at end of file diff --git a/app/store/controller/cart/CartController.php b/app/store/controller/cart/CartController.php index 29d3cf937..3674f732e 100644 --- a/app/store/controller/cart/CartController.php +++ b/app/store/controller/cart/CartController.php @@ -7,6 +7,7 @@ use app\api\validate\CartValidate; use app\common\model\store_branch_product\StoreBranchProduct; use app\store\lists\cart\CartList; use app\common\model\order\Cart; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\store\controller\BaseAdminController; @@ -30,10 +31,9 @@ class CartController extends BaseAdminController $params['store_id'] = $adminInfo['store_id']; $result = Cart::where(['uid' => 0, 'staff_id' => $adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find(); //判断起批发价 - $branchProduct = StoreBranchProduct::where( + $branchProduct = StoreProduct::where( [ - 'product_id' => $params['product_id'], - 'store_id' => $adminInfo['store_id'] + 'id' => $params['product_id'], ] )->find(); if ($params['cart_num'] < $branchProduct['batch']) { @@ -76,6 +76,18 @@ class CartController extends BaseAdminController { $params = (new CartValidate())->post()->goCheck('StoreChange'); $adminInfo = $this->adminInfo; + $params['cart_num']=bcadd($params['cart_num'],0,2); + if (convertNumber($params['cart_num']) === false) { + $branchProduct = StoreProduct::where( + [ + 'id' => $params['product_id'], + ] + )->find(); + $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); + if ($is_bulk == 0) { + return $this->fail('非计量商品,不能有小数,请编辑购物车'); + } + } $params['uid'] = 0; $params['staff_id'] = $adminInfo['admin_id']; $params['store_id'] = $adminInfo['store_id']; diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index d5b269ac7..e03a0b68f 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -542,4 +542,24 @@ class StoreOrderController extends BaseAdminController return $this->fail('订单支付中'); } } + + /** + * 不配送核销 + */ + public function noDelivery(){ + $id=$this->request->post('id'); + if($id){ + $params = StoreOrder::where('id', $id)->find(); + if (!$params) { + return $this->fail('无该核销码请检查'); + } + $params['store_id'] = $this->adminInfo['store_id']; + $params['staff_id'] = $this->adminId; + $res = OrderLogic::writeOff($params); + if ($res) { + return $this->success('核销成功'); + } + return $this->fail('核销失败' . OrderLogic::getError()); + } + } } diff --git a/app/store/lists/cart/CartList.php b/app/store/lists/cart/CartList.php index 27ca4ecf3..f136bdfcc 100644 --- a/app/store/lists/cart/CartList.php +++ b/app/store/lists/cart/CartList.php @@ -12,6 +12,7 @@ use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; use app\common\lists\ListsExtendInterface; +use app\common\model\store_product\StoreProduct; /** * 购物车列表 @@ -48,7 +49,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists 'is_pay' => 0 ]; $list = Cart::where($this->searchWhere)->where($where) - ->limit($this->limitOffset, $this->limitLength) + ->limit(100) ->order(['id' => 'desc']) ->select()->each(function ($item) { @@ -70,8 +71,8 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists } } foreach ($list as $key => &$item) { - $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) - ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id') + $find = StoreProduct::where(['id' => $item['product_id']]) + ->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id') ->find(); if ($find) { if ($off_activity == 1) { @@ -90,7 +91,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists $item['image'] = $find['image']; $item['cost'] = $find['cost']; $item['store_name'] = $find['store_name']; - $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $unit = StoreProductUnit::where('id', $find['unit'])->find(); + if($unit){ + $item['unit_name']=$unit['name']; + $item['is_bulk']=$unit['is_bulk']; + }else{ + $item['unit_name']=''; + $item['is_bulk']=0; + } } } return $list; diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 10faeb625..bcb3fffb7 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -74,22 +74,24 @@ class WorkbenchLogic extends BaseLogic //余额支付总金额 $data['balance_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::BALANCE_PAY])); //微信条码支付总金额 - $data['wechat_code_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::WECHAT_PAY_BARCODE])); + $data['wechat_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => [7,9]])); //支付条码支付总金额 - $data['alipay_code_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::ALIPAY_BARCODE])); + $data['alipay_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::ALIPAY_BARCODE])); + //采购款 + $data['purchase_funds_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::PURCHASE_FUNDS])); + //现金 + $data['cash_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::CASH_PAY])); //线下收银总金额 - $data['cashier_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 3])); + // $data['cashier_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 3])); //现金收银总金额 - $data['cash_amount'] = StoreCashFinanceFlow::where($cashFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price'); + // $data['cash_amount'] = StoreCashFinanceFlow::where($cashFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price'); //核销订单金额 - $data['verify_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 2])); + // $data['verify_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 2])); //门店收益金额 $data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); //门店收款金额 - $all_where['paid'] = 1; -// $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())); - $data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime); -// $data['receipt_amount'] = UserRecharge::where($userRechargeWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('price'); + // $all_where['paid'] = 1; + // $data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime); //保证金金额 $data['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhereTwo)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); /**门店损耗金 */ @@ -140,7 +142,7 @@ class WorkbenchLogic extends BaseLogic $data['order_list'] = StoreOrder::with('user')->where($where) // ->whereBetweenTime('pay_time', $startTime, $endTime) ->order('pay_time', 'desc') -// ->limit(6) + ->limit(10) ->select()->each(function($item){ $item->pay_time=$item->pay_time>0?date('Y-m-d H:i:s',$item->pay_time):''; }) @@ -156,31 +158,31 @@ class WorkbenchLogic extends BaseLogic ->select() ->toArray(); - $orderList = StoreOrder::field($field) - ->where($where) - ->whereBetweenTime('pay_time', $startTime, $endTime) - ->group($group) - ->select() - ->toArray(); + // $orderList = StoreOrder::field($field) + // ->where($where) + // ->whereBetweenTime('pay_time', $startTime, $endTime) + // ->group($group) + // ->select() + // ->toArray(); $userList = StoreOrder::field($field . ',count(uid) as user_num') ->where($where) ->whereBetweenTime('pay_time', $startTime, $endTime) ->group($group . ',uid') ->select() ->toArray(); - $orderList = reset_index($orderList, 'pay_time'); + // $orderList = reset_index($orderList, 'pay_time'); $userList = reset_index($userList, 'pay_time'); - $orderListTmp = []; + // $orderListTmp = []; $userListTmp = []; $range = []; $mergedListTmp = []; foreach ($timeRange as $item) { $range[] = $item; - if (!isset($orderList[$item])) { - $orderListTmp[$item] = 0; - } else { - $orderListTmp[$item] = $orderList[$item]['pay_price']; - } + // if (!isset($orderList[$item])) { + // $orderListTmp[$item] = 0; + // } else { + // $orderListTmp[$item] = $orderList[$item]['pay_price']; + // } if (!isset($userList[$item])) { $userListTmp[$item] = 0; } else { @@ -194,25 +196,29 @@ class WorkbenchLogic extends BaseLogic $mergedListTmp[$item] += $recharge['pay_price']; } } - foreach ($orderList as $order) { - if ($order['pay_time'] == $item) { - $mergedListTmp[$item] += $order['pay_price']; - } - } + // foreach ($orderList as $order) { + // if ($order['pay_time'] == $item) { + // $mergedListTmp[$item] += $order['pay_price']; + // } + // } } $data['statistics'] = [ 'range' => $range, 'data' => [ // 'order_amount' => array_values($orderListTmp), 'user_number' => array_values($userListTmp), - 'order_amount' => array_values($mergedListTmp) + // 'order_amount' => array_values($mergedListTmp) ] ]; $data['pay_type'] = [ - ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], - ['name' => '核销订单', 'value' => $data['verify_amount']], - ['name' => '现金收银订单', 'value' => $data['cash_amount']], + // ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], + // ['name' => '核销订单', 'value' => $data['verify_amount']], + ['name' => '微信订单', 'value' => $data['wechat_amount']], + ['name' => '支付宝订单', 'value' => $data['alipay_amount']], + ['name' => '采购款订单', 'value' => $data['purchase_funds_amount']], + ['name' => '余额订单', 'value' => $data['balance_amount']], + ['name' => '现金订单', 'value' => $data['cash_amount']], ]; return $data; } diff --git a/app/store/logic/auth/AdminLogic.php b/app/store/logic/auth/AdminLogic.php index fd63d0ef4..9f8af98bc 100644 --- a/app/store/logic/auth/AdminLogic.php +++ b/app/store/logic/auth/AdminLogic.php @@ -25,6 +25,7 @@ use app\common\model\auth\AdminSession; use app\common\cache\AdminTokenCache; use app\common\model\system_store\SystemStoreStaff; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; use think\facade\Db; @@ -73,8 +74,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -141,8 +141,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -180,8 +179,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/auth/RoleLogic.php b/app/store/logic/auth/RoleLogic.php index e0113d50b..adb39bee9 100644 --- a/app/store/logic/auth/RoleLogic.php +++ b/app/store/logic/auth/RoleLogic.php @@ -20,6 +20,7 @@ use app\common\{ logic\BaseLogic, model\auth\SystemRoleMenu }; +use support\exception\BusinessException; use think\facade\Db; @@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_branch_product/StoreBranchProductLogic.php b/app/store/logic/store_branch_product/StoreBranchProductLogic.php index d37e60cad..7837ac1b5 100644 --- a/app/store/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/store/logic/store_branch_product/StoreBranchProductLogic.php @@ -65,8 +65,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -95,8 +94,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -151,7 +149,7 @@ class StoreBranchProductLogic extends BaseLogic public static function checkAuth($product) { if (request()->adminInfo['store_id'] != $product['store_id']) { - throw new \Exception('没有权限操作'); + throw new BusinessException('没有权限操作'); } } diff --git a/app/store/logic/store_order/StoreOrderLogic.php b/app/store/logic/store_order/StoreOrderLogic.php index 80df42e05..13b7948a0 100644 --- a/app/store/logic/store_order/StoreOrderLogic.php +++ b/app/store/logic/store_order/StoreOrderLogic.php @@ -7,6 +7,7 @@ use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -38,8 +39,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -63,8 +63,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_product/StoreProductLogic.php b/app/store/logic/store_product/StoreProductLogic.php index 7af0b7980..594a72821 100644 --- a/app/store/logic/store_product/StoreProductLogic.php +++ b/app/store/logic/store_product/StoreProductLogic.php @@ -7,6 +7,7 @@ use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_attr_value\StoreProductAttrValue; +use support\exception\BusinessException; use think\facade\Db; @@ -34,8 +35,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -58,8 +58,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php index 2520412a2..0572ba6ce 100644 --- a/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php +++ b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -5,6 +5,7 @@ namespace app\store\logic\store_product_attr_value; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/validate/LoginValidate.php b/app/store/validate/LoginValidate.php index b7c80593f..89b79407b 100644 --- a/app/store/validate/LoginValidate.php +++ b/app/store/validate/LoginValidate.php @@ -10,7 +10,7 @@ use app\common\model\auth\Admin; use app\common\model\system_store\SystemStoreStaff; use app\common\service\ConfigService; use app\common\validate\BaseValidate; -use app\MyBusinessException; +use support\exception\BusinessException; use Webman\Config; class LoginValidate extends BaseValidate @@ -55,7 +55,7 @@ class LoginValidate extends BaseValidate //后台账号安全机制,连续输错后锁定,防止账号密码暴力破解 if ($config['login_restrictions'] == 1 && !$adminAccountSafeCache->isSafe()) { - throw new MyBusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试'); + throw new BusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试'); } $staffInfo = SystemStoreStaff::where('account', '=', $data['account']) @@ -63,21 +63,21 @@ class LoginValidate extends BaseValidate ->findOrEmpty(); if ($staffInfo->isEmpty()) { - return '账号不存在'; + throw new BusinessException('账号不存在'); } if ($staffInfo['disable'] === 1) { - return '账号已禁用'; + throw new BusinessException('账号已禁用'); } if (empty($staffInfo['pwd'])) { $adminAccountSafeCache->record(); - return '账号不存在'; + throw new BusinessException('账号不存在'); } $pwdSalt = Config::get('project.unique_identification'); if ($staffInfo['pwd'] !== create_password($password, $pwdSalt)) { $adminAccountSafeCache->record(); - return '密码错误'; + throw new BusinessException('密码错误'); } $adminAccountSafeCache->relieve(); diff --git a/composer.json b/composer.json index d15c2d391..c9b3a5826 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": ">=8.1", "workerman/webman-framework": "^1.5.22", "monolog/monolog": "^2.2", - "webman/think-orm": "v1.1.1", + "webman/think-orm": "v1.1.3", "vlucas/phpdotenv": "^5.4", "psr/container": "^1.1.1", "ext-json": "*", diff --git a/composer.lock b/composer.lock index ee9fc1370..1fe62351d 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": "fb2dcd2b6d5f80016cfae906588f8bb9", + "content-hash": "883e9ccf0087df3fcbef974d5c9317f3", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -7319,23 +7319,17 @@ }, { "name": "webman/think-orm", - "version": "v1.1.1", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/webman-php/think-orm.git", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2" + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webman-php/think-orm/zipball/9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] + "url": "https://api.github.com/repos/webman-php/think-orm/zipball/1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "shasum": "" }, "require": { "topthink/think-orm": "^2.0.53 || ^3.0.0", @@ -7353,9 +7347,9 @@ ], "support": { "issues": "https://github.com/webman-php/think-orm/issues", - "source": "https://github.com/webman-php/think-orm/tree/v1.1.1" + "source": "https://github.com/webman-php/think-orm/tree/v1.1.3" }, - "time": "2023-04-23T14:40:18+00:00" + "time": "2024-08-14T03:46:14+00:00" }, { "name": "webmozart/assert", diff --git a/config/log.php b/config/log.php index ee8448c4a..1b75ae61d 100644 --- a/config/log.php +++ b/config/log.php @@ -1,4 +1,5 @@ [ 'class' => Monolog\Formatter\LineFormatter::class, - 'constructor' => [null, 'Y-m-d H:i:s', true,true], + 'constructor' => [null, 'Y-m-d H:i:s', true, true], + ], + ] + ], + ], + // log2通道 + 'product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/product/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'branch_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/branch_product/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'product_storege' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/product_storege/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'user' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/user/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'system_store' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/system_store/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_finance_flow' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_finance_flow/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_finance_flow_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_finance_flow_product/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_order' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_order/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_order_cart_info' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_order_cart_info/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'warehouse_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/warehouse_product/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'warehouse_product_storege' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/warehouse_product_storege/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], ], ] ], diff --git a/process/Task.php b/process/Task.php index 2fedfff83..a25bda15f 100644 --- a/process/Task.php +++ b/process/Task.php @@ -23,7 +23,7 @@ class Task new Crontab('0 */10 * * * *', function () { $where = ['paid' => 0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 - $where[] = ['shipping_type', '<>',4]; + $where[] = ['source', '<',2]; // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 if ($oid) { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index be31e2968..abc2e61cb 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -7268,24 +7268,24 @@ }, { "name": "webman/think-orm", - "version": "v1.1.1", - "version_normalized": "1.1.1.0", + "version": "v1.1.3", + "version_normalized": "1.1.3.0", "source": { "type": "git", "url": "https://github.com/webman-php/think-orm.git", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2" + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webman-php/think-orm/zipball/9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", + "url": "https://api.github.com/repos/webman-php/think-orm/zipball/1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6", "shasum": "" }, "require": { "topthink/think-orm": "^2.0.53 || ^3.0.0", "workerman/webman-framework": "^1.2.1" }, - "time": "2023-04-23T14:40:18+00:00", + "time": "2024-08-14T03:46:14+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -7299,7 +7299,7 @@ ], "support": { "issues": "https://github.com/webman-php/think-orm/issues", - "source": "https://github.com/webman-php/think-orm/tree/v1.1.1" + "source": "https://github.com/webman-php/think-orm/tree/v1.1.3" }, "install-path": "../webman/think-orm" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 12dfcbab0..84d6169e2 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -993,9 +993,9 @@ 'dev_requirement' => false, ), 'webman/think-orm' => array( - 'pretty_version' => 'v1.1.1', - 'version' => '1.1.1.0', - 'reference' => '9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2', + 'pretty_version' => 'v1.1.3', + 'version' => '1.1.3.0', + 'reference' => '1c20a9bbedf8a3c0b741f19b175eb929907101c6', 'type' => 'library', 'install_path' => __DIR__ . '/../webman/think-orm', 'aliases' => array(), diff --git a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php index b362856bf..23e33a878 100644 --- a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php +++ b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php @@ -75,7 +75,6 @@ trait ModelEvent } $call = 'on' . Str::studly($event); - try { if (method_exists(static::class, $call)) { $result = call_user_func([static::class, $call], $this); diff --git a/vendor/webman/think-orm/src/ThinkOrm.php b/vendor/webman/think-orm/src/ThinkOrm.php index a5e2f13d2..c35a53e5d 100644 --- a/vendor/webman/think-orm/src/ThinkOrm.php +++ b/vendor/webman/think-orm/src/ThinkOrm.php @@ -40,7 +40,7 @@ class ThinkOrm implements Bootstrap } foreach ($instances as $connection) { /* @var \think\db\connector\Mysql $connection */ - if (in_array($connection->getConfig('type'), ['mysql', 'oracle', 'sqlsrv'])) { + if (in_array($connection->getConfig('type'), ['mysql', 'oracle', 'sqlsrv']) && method_exists($connection, 'getPdo') && $connection->getPdo()) { try { $connection->query('select 1'); } catch (Throwable $e) {} diff --git a/vendor/webman/think-orm/src/config/thinkorm.php b/vendor/webman/think-orm/src/config/thinkorm.php index 37af444bb..8cb83de7e 100644 --- a/vendor/webman/think-orm/src/config/thinkorm.php +++ b/vendor/webman/think-orm/src/config/thinkorm.php @@ -27,8 +27,6 @@ return [ 'prefix' => '', // 断线重连 'break_reconnect' => true, - // 关闭SQL监听日志 - 'trigger_sql' => false, // 自定义分页类 'bootstrap' => '' ],