From 5d24bbe2a0769cbf0ec97b71e4e0c193ba691e86 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 3 Jun 2024 16:09:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(PayController):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=8E=A7=E5=88=B6=E5=99=A8=E4=BB=A5=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=BE=AE=E4=BF=A1=E9=80=9A=E7=94=A8=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/PayController.php | 6 +- app/common/enum/OrderEnum.php | 84 +++++++++++ app/common/logic/PayNotifyLogic.php | 136 +++++------------- .../financial_record/FinancialRecord.php | 22 +++ 4 files changed, 141 insertions(+), 107 deletions(-) create mode 100644 app/common/enum/OrderEnum.php create mode 100644 app/common/model/financial_record/FinancialRecord.php diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index 715cb053b..faa2dfd20 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -31,8 +31,8 @@ class PayController extends BaseApiController $extra['transaction_id'] = $ciphertext['transaction_id']; $attach = $ciphertext['attach']; switch ($attach) { - case 'cashierclass': - PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext); + case 'wechat_common': + PayNotifyLogic::handle('wechat_common', $ciphertext['out_trade_no'], $ciphertext); $app->wechat->success(); break; } @@ -53,7 +53,7 @@ class PayController extends BaseApiController $res = $app->wechat->query($order); if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { - PayNotifyLogic::handle('cashierclass', $res['out_trade_no'], $res); + PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); return $this->success('支付成功'); } else { return $this->fail('订单支付中'); diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php new file mode 100644 index 000000000..0753b46e0 --- /dev/null +++ b/app/common/enum/OrderEnum.php @@ -0,0 +1,84 @@ +'用户订单支付', + self::MERCHANT_ORDER_PAY=>'商户订单支付', + self::PLATFORM_ORDER_PAY=>'平台订单支付', + self::MERCHANT_ORDER_OBTAINS=>'商户订单获得', + self::ORDER_HANDLING_FEES=>'订单手续费', + self::PLATFORM_ORDER_OBTAINS=>'平台订单获得', + self::SUPPLIER_ORDER_OBTAINS=>'供应商订单获得', + self::SYSTEM_SET=>'平台设置', + + + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } + + +} \ No newline at end of file diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 7421be36e..d2f9a71f9 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -7,9 +7,11 @@ use app\common\enum\PayEnum; use app\common\enum\user\AccountLogEnum; use app\common\model\operation\Opurchaseclass; use app\common\model\order\Cart; -use app\common\model\order\FinancialRecord; +use app\common\model\financial_record\FinancialRecord; use app\common\model\recharge\RechargeOrder; use app\common\model\retail\Cashierclass; +use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\store_order\StoreOrder; use app\common\model\user\User; use app\common\service\PushService; use app\common\service\wechat\WeChatMnpService; @@ -48,15 +50,14 @@ class PayNotifyLogic extends BaseLogic /** - * @notes 零售回调 + * @notes 微信通用回调 * @param $orderSn * @param array $extra - * @author 段誉 * @date 2023/2/27 15:28 */ - public static function cashierclass($orderSn, $extra = []) + public static function wechat_common($orderSn, $extra = []) { - $order = Cashierclass::where('number', $orderSn)->findOrEmpty(); + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { return true; @@ -64,7 +65,7 @@ class PayNotifyLogic extends BaseLogic $financial_type = OrderEnum::USER_ORDER_PAY; $financial_type2 = OrderEnum::MERCHANT_ORDER_OBTAINS; if ($order->pay_type != 10) { - $order->money = bcdiv($extra['amount']['payer_total'], 100, 2); + $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); $order->paid = 1; $order->status = 1; $order->save(); @@ -81,128 +82,54 @@ class PayNotifyLogic extends BaseLogic $record[] = [ 'financial_record_sn' => $extra['transaction_id'], 'order_id' => $order['id'], - 'number_sn' => $order['number'], + 'order_sn' => $order['order_id'], 'user_id' => $order['uid'], 'financial_type' => $financial_type, 'financial_pm' => OrderEnum::EXPENDITURE, - 'number' => $order['actual'], + 'number' => $order['pay_price'], 'status' => 1, 'type' => OrderEnum::USER, - 'mer_id' => $order['merchant'], + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], ]; } //商户获得流水 $record[] = [ 'financial_record_sn' => $extra['transaction_id'], 'order_id' => $order['id'], - 'number_sn' => $order['number'], + 'order_sn' => $order['order_id'], 'user_id' => $order['uid'], 'financial_type' => $financial_type2, 'financial_pm' => OrderEnum::INCOME, - 'number' => $order['actual'], + 'number' => $order['pay_price'], 'status' => 0, 'type' => OrderEnum::MERCHANT, - 'mer_id' => $order['merchant'], + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], ]; (new FinancialRecord())->saveAll($record); if ($order->pay_type == 9) { $extra['create_time'] = $order['create_time']; - PushService::push('store_merchant_' . $order['merchant'], $order['merchant'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); + PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); } else { - PushService::push('store_merchant_' . $order['merchant'], $order['merchant'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); Redis::send('push-platform-print', ['order_id' => $order['id']], 60); - Db::name('order_middle')->insert(['c_order_id' =>$order['id']]); + Db::name('order_middle')->insert(['c_order_id' => $order['id']]); } if (!empty($extra['payer']['openid']) && $order->pay_type != 9) { - Redis::send('push-delivery', ['order_id' => $orderSn, 'openid' => $extra['payer']['openid']], 5); + Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5); } return true; } - /** - * 采购订单支付成功 - */ - public static function opurchaseclass($orderSn, $extra = []) - { - $order = Opurchaseclass::where('number', $orderSn)->findOrEmpty(); - $order_arr = explode(',', $order['order_arr']); - (new FinancialRecord())->where('order_id', 'in', $order_arr)->update(['status' => 1]); - Db::name('order_middle')->where('c_order_id', 'in', $order_arr)->update(['b_order_id' => $order['id']]); - $time = time(); - //商户支出流水 - $record[] = [ - 'financial_record_sn' => $time, - 'order_id' => $order['id'], - 'number_sn' => $order['number'], - 'user_id' => $order['uid'], - 'financial_type' => OrderEnum::MERCHANT_ORDER_PAY, - 'financial_pm' => OrderEnum::EXPENDITURE, - 'number' => $order['actual'], - 'status' => 1, - 'type' => OrderEnum::MERCHANT, - 'mer_id' => $order['merchant'], - ]; - //平台获得流水 - $record[] = [ - 'financial_record_sn' => $time, - 'order_id' => $order['id'], - 'number_sn' => $order['number'], - 'user_id' => $order['uid'], - 'financial_type' => OrderEnum::PLATFORM_ORDER_OBTAINS, - 'financial_pm' => OrderEnum::INCOME, - 'number' => $order['actual'], - 'status' => 1, - 'type' => OrderEnum::PLATFORM, - 'mer_id' => $order['merchant'], - ]; - (new FinancialRecord())->saveAll($record); - } - - /** - * 平台采购订单支付成功 - */ - public static function operated($orderSn, $extra = []) - { - $order = Opurchaseclass::where('number', $orderSn)->findOrEmpty(); - $order_arr = explode(',', $order['order_arr']); - (new FinancialRecord())->where('order_id', 'in', $order_arr)->update(['status' => 1]); - Db::name('order_middle')->where('b_order_id', 'in', $order_arr)->update(['p_order_id' => $order['id']]); - $time = time(); - //平台支出流水 - $record[] = [ - 'financial_record_sn' => $time, - 'order_id' => $order['id'], - 'number_sn' => $order['number'], - 'user_id' => $order['uid'], - 'financial_type' => OrderEnum::PLATFORM_ORDER_PAY, - 'financial_pm' => OrderEnum::EXPENDITURE, - 'number' => $order['actual'], - 'status' => 1, - 'type' => OrderEnum::PLATFORM, - 'mer_id' => getenv('OPERATED'), - ]; - // //平台获得流水 - // $record[] = [ - // 'financial_record_sn' => $time, - // 'order_id' => $order['id'], - // 'number_sn' => $order['number'], - // 'user_id' => $order['uid'], - // 'financial_type' => OrderEnum::PLATFORM_ORDER_OBTAINS, - // 'financial_pm' => OrderEnum::INCOME, - // 'number' => $order['actual'], - // 'status' => 1, - // 'type' => OrderEnum::PLATFORM, - // 'mer_id' => $order['merchant'], - // ]; - (new FinancialRecord())->saveAll($record); - } + /** * 现金支付 */ public static function cash_pay($orderSn) { - $order = Cashierclass::where('number', $orderSn)->findOrEmpty(); + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { return true; @@ -214,19 +141,20 @@ class PayNotifyLogic extends BaseLogic $record[] = [ 'financial_record_sn' => time(), 'order_id' => $order['id'], - 'number_sn' => $order['number'], + 'order_sn' => $order['order_id'], 'user_id' => $order['uid'], 'financial_type' => OrderEnum::CASHIER_CASH_ORDER_PAY, 'financial_pm' => OrderEnum::INCOME, - 'number' => $order['actual'], + 'number' => $order['pay_price'], 'status' => 1, 'type' => OrderEnum::MERCHANT, - 'mer_id' => $order['merchant'], + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], ]; (new FinancialRecord())->saveAll($record); } - /** + /** * @notes 零售回调 * @param $orderSn * @param array $extra @@ -235,7 +163,7 @@ class PayNotifyLogic extends BaseLogic */ public static function alipay_cashier($orderSn, $extra = []) { - $order = Cashierclass::where('number', $orderSn)->findOrEmpty(); + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { return true; @@ -260,7 +188,7 @@ class PayNotifyLogic extends BaseLogic $record[] = [ 'financial_record_sn' => $extra['trade_no'], 'order_id' => $order['id'], - 'number_sn' => $order['number'], + 'order_sn' => $order['order_id'], 'user_id' => $order['uid'], 'financial_type' => $financial_type, 'financial_pm' => OrderEnum::EXPENDITURE, @@ -274,7 +202,7 @@ class PayNotifyLogic extends BaseLogic $record[] = [ 'financial_record_sn' => $extra['trade_no'], 'order_id' => $order['id'], - 'number_sn' => $order['number'], + 'order_sn' => $order['order_id'], 'user_id' => $order['uid'], 'financial_type' => $financial_type2, 'financial_pm' => OrderEnum::INCOME, @@ -288,10 +216,10 @@ class PayNotifyLogic extends BaseLogic if ($order->pay_type == 9) { $extra['create_time'] = $order['create_time']; - PushService::push('store_merchant_' . $order['merchant'], $order['merchant'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); + PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); } else { - PushService::push('store_merchant_' . $order['merchant'], $order['merchant'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - Redis::send('push-platform-print', ['order_id' => $order['id']], 60); + PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + Redis::send('push-platform-print', ['order_sn' => $order['order_id']], 60); } return true; } diff --git a/app/common/model/financial_record/FinancialRecord.php b/app/common/model/financial_record/FinancialRecord.php new file mode 100644 index 000000000..d6bb48eda --- /dev/null +++ b/app/common/model/financial_record/FinancialRecord.php @@ -0,0 +1,22 @@ + Date: Mon, 3 Jun 2024 16:11:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=92=8C=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/product/ProductController.php | 25 ++ app/api/lists/product/ProductLists.php | 215 ++++++++++++++++++ app/api/logic/order/OrderLogic.php | 32 +-- .../StoreBranchProduct.php | 18 ++ .../model/store_product/StoreProduct.php | 11 +- 5 files changed, 285 insertions(+), 16 deletions(-) create mode 100644 app/api/controller/product/ProductController.php create mode 100644 app/api/lists/product/ProductLists.php diff --git a/app/api/controller/product/ProductController.php b/app/api/controller/product/ProductController.php new file mode 100644 index 000000000..d956a9b70 --- /dev/null +++ b/app/api/controller/product/ProductController.php @@ -0,0 +1,25 @@ +dataLists(new ProductLists()); + } + + /** + * 商品列表 + */ + public function mer_list(){ + $this->request->__set('mer_id',$this->request->userInfo['merchant']['mer_id']??0); + return $this->dataLists(new ProductLists()); + } + +} \ No newline at end of file diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php new file mode 100644 index 000000000..affc9f344 --- /dev/null +++ b/app/api/lists/product/ProductLists.php @@ -0,0 +1,215 @@ +request->get('name'); +// $where= [ +// '=' => ['class'] +// ]; +// if($name && preg_match('/[\x{4e00}-\x{9fff}]+/u', $name)==1){ +// $where['%like%']=['store_name']; + $where[] = ['store_name','like','%'.$name.'%']; +// }else{ +// $where['=']=['bar_code','cate_id']; +// } + return $where; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { +// return ['sell' => 'sell', 'sales' => 'sales',]; + return ['sell' => 'ot_price', 'sales' => 'sales',]; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['sales' => 'desc','ot_price' => 'asc']; + } + + /** + * @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 + { + $class_all=$this->request->get('class_all'); + $name = $this->request->get('name',''); + $order_param = $this->request->get('order'); + $store_id = $this->request->get('store_id',2); + $where=[]; + $order = []; + if($class_all){ + $arr=[]; + $arr2=[]; + $arr=Cate::where('pid',$class_all)->column('id'); + if($arr){ + $arr2=Cate::where('pid','in',$arr)->column('id'); + $where[]=['cate_id','in',array_merge($arr,$arr2)]; + }else{ + $where[]=['cate_id','=',$class_all]; + } + + } + if(!empty($order_param)){ + if($order_param == 'asc'){ + $order['price'] = 'asc'; + }elseif ($order_param == 'desc') { + $order['price'] = 'desc'; + }elseif ($order_param=='sales') { + $order['sales'] = 'desc'; + } + }else{ + $order['id'] = 'desc'; + } + if($name){ + if(preg_match('/[\x{4e00}-\x{9fff}]+/u', $name)==1){ + $where[] = ['store_name','like','%'.$name.'%']; + }else{ + $where[] = ['bar_code','=',$name]; + } + + } + $where[]=['store_id','=',$store_id]; + $data =StoreBranchProduct::where($this->searchWhere)->where($where) + ->field(['id', 'product_id','cate_id','store_name', 'store_id','price', 'bar_code','image','sales','store_info','delete_time']) + ->limit($this->limitOffset, $this->limitLength) + ->with(['className']) + ->order($order) + ->select() + ->toArray(); + foreach ($data as $k=> &$v){ + $info= StoreProduct::alias('p') + ->leftJoin('store_product_unit t','t.id = p.unit') + ->where('p.id',$v['product_id']) + ->field('p.unit,t.name,t.is_bulk')->find()??[]; + if($info){ + $v['unit_name'] = $info['name']??''; + $v['is_bulk'] = $info['is_bulk']??''; + }else{ + unset($data[$k]); + } + } + return array_values($data); +// return StoreProduct::where($this->searchWhere)->where($where) +// ->field(['id', 'cate_id','store_name','unit', 'ot_price', 'bar_code','image','sales','store_info']) +// ->limit($this->limitOffset, $this->limitLength) +// ->with(['className','unitName']) +// ->order($order) +// ->select() +// ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + $class_all=$this->request->get('class_all'); + $order_param = $this->request->get('order'); + $store_id = $this->request->get('store_id',2); + $name = $this->request->get('name',''); + $where=[]; + $order = []; + if($class_all){ + $arr=[]; + $arr2=[]; + $arr=Cate::where('pid',$class_all)->column('id'); + if($arr){ + $arr2=Cate::where('pid','in',$arr)->column('id'); + $where[]=['cate_id','in',array_merge($arr,$arr2)]; + }else{ + $where[]=['cate_id','=',$class_all]; + } + + } + if(!empty($order_param)){ + if($order_param == 'asc'){ + $order['price'] = 'asc'; + }elseif ($order_param == 'desc') { + $order['price'] = 'desc'; + }elseif ($order_param=='sales') { + $order['sales'] = 'desc'; + } + }else{ + $order['id'] = 'desc'; + } + + if($name){ + if(preg_match('/[\x{4e00}-\x{9fff}]+/u', $name)==1){ + $where[] = ['store_name','like','%'.$name.'%']; + }else{ + $where[] = ['bar_code','=',$name]; + } + + } + $where[]=['store_id','=',$store_id]; + + $data =StoreBranchProduct::where($this->searchWhere)->where($where) + ->field(['id', 'product_id']) + ->order($order) + ->select() + ->toArray(); + foreach ($data as $k=> &$v){ + $info= StoreProduct::alias('p') + ->leftJoin('store_product_unit t','t.id = p.unit') + ->where('p.id',$v['product_id']) + ->field('p.unit,t.name,t.is_bulk')->find()??[]; + if($info){ + $v['unit_name'] = $info['name']??''; + $v['is_bulk'] = $info['is_bulk']??''; + }else{ + unset($data[$k]); + } + } + + + return count($data); + } + +} \ No newline at end of file diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index a9abe3447..4e830352f 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -41,8 +41,8 @@ class OrderLogic extends BaseLogic static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = []) { - $where = ['is_pay' => 0, 'is_fail' => 0]; - $cart_select = Cart::whereIn('cart_id', $cartId)->where($where)->field('goods_id as goods,cart_num')->select()->toArray(); + $where = ['is_pay' => 0, 'is_del' => 0]; + $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('product_id as goods,cart_num')->select()->toArray(); if (empty($cart_select)) { self::setError('购物车为空'); return false; @@ -51,24 +51,26 @@ class OrderLogic extends BaseLogic self::$total = 0; /** 计算价格 */ foreach ($cart_select as $k => $v) { - $find = Goods::where(['id' => $v['goods']])->field('name,imgs,unit,sell')->find(); + $find = StoreProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price')->find(); if(!$find){ continue; } - $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['sell'], 2); - $cart_select[$k]['price'] = $find['sell']; - $cart_select[$k]['name'] = $find['name']; - $cart_select[$k]['imgs'] = $find['imgs']; - $cart_select[$k]['unit_name'] = Unit::where(['id' => $find['unit']])->value('name'); + $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 + $cart_select[$k]['price'] = $find['price']; + $cart_select[$k]['name'] = $find['store_name']; + $cart_select[$k]['imgs'] = $find['image']; + $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); self::$total=bcadd(self::$total, $cart_select[$k]['total'], 2); } $order = [ - 'time' => time(), - 'number' => getNewOrderId('PF'), - 'total' => self::$total, + 'add_time' => time(), + 'create_time' => time(), + 'order_id' => getNewOrderId('PF'), + 'total_price' => self::$total,//总价 + 'total_num' => count($cart_select),//总数 'pay_type' => $params['pay_type'] ?? 0, 'cart_id' => implode(',', $cartId), - 'delivery_msg'=>' 预计48小时发货 ' +// 'delivery_msg'=>' 预计48小时发货 ' ]; } catch (\Exception $e) { self::setError($e->getMessage()); @@ -115,7 +117,7 @@ class OrderLogic extends BaseLogic } Db::startTrans(); try { - $order = Cashierclass::create($_order); + $order = StoreOrder::create($_order); $goods_list = $orderInfo['cart_list']; foreach ($goods_list as $k => $v) { $goods_list[$k]['pid'] = $order->id; @@ -126,8 +128,8 @@ class OrderLogic extends BaseLogic $goods_list[$k]['warehouse'] = 0; $goods_list[$k]['nums'] = $v['cart_num']; } - (new Cashierinfo())->saveAll($goods_list); - $where = ['is_pay' => 0, 'is_fail' => 0]; + (new StoreOrderCartInfo())->saveAll($goods_list); + $where = ['is_pay' => 0, 'is_del' => 0]; Cart::whereIn('cart_id', $cartId)->where($where)->update(['is_pay'=>1]); Db::commit(); return $order; diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index 4f988320e..dfca1be35 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -4,6 +4,9 @@ namespace app\common\model\store_branch_product; 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 think\model\concern\SoftDelete; @@ -18,5 +21,20 @@ class StoreBranchProduct extends BaseModel protected $name = 'store_branch_product'; protected $deleteTime = 'delete_time'; + + + + public function className() + { + return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); + + + } + + + public function store() + { + return $this->hasOne(StoreProduct::class,'id','product_id'); + } } \ No newline at end of file diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index 639635600..dc810fdda 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -4,6 +4,7 @@ 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 think\model\concern\SoftDelete; @@ -25,5 +26,13 @@ class StoreProduct extends BaseModel return $this->hasOne(StoreProductUnit::class,'id','unit')->bind(['unit_name'=>'name','is_bulk']); } - + + public function className() + { + return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); + + + } + + } \ No newline at end of file