From 4cf9124a85cf79ef2864f5c420ff8df36f41342c Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 5 Jun 2024 11:00:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_order/StoreOrderLists.php | 11 ++- app/common/controller/Definitions.php | 26 ++++++ .../StoreBranchProductAttrValue.php | 9 +- .../StoreProductAttrValueController.php | 92 +++++++++++-------- .../StoreProductAttrValueLists.php | 10 +- 5 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 app/common/controller/Definitions.php diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index e1e33cacb..4f3bde68d 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -44,6 +44,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { return StoreOrder::where($this->searchWhere) + ->when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -63,7 +66,11 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return StoreOrder::where($this->searchWhere)->count(); + return StoreOrder::where($this->searchWhere) + ->when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) + ->count(); } -} \ No newline at end of file +} diff --git a/app/common/controller/Definitions.php b/app/common/controller/Definitions.php new file mode 100644 index 000000000..8e1e81085 --- /dev/null +++ b/app/common/controller/Definitions.php @@ -0,0 +1,26 @@ +hasOne(StoreProductAttrValue::class, 'unique', 'unique')->bind(['image']); + } + +} diff --git a/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php b/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php index 86ccaddb9..ae7c08238 100644 --- a/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php +++ b/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php @@ -3,12 +3,12 @@ namespace app\store\controller\store_product_attr_value; +use app\common\controller\Definitions; use app\store\controller\BaseAdminController; use app\store\lists\store_product_attr_value\StoreProductAttrValueLists; use app\store\logic\store_product_attr_value\StoreProductAttrValueLogic; use app\store\validate\store_product_attr_value\StoreProductAttrValueValidate; use hg\apidoc\annotation as ApiDoc; -#[ApiDoc\NotParse()] /** @@ -16,28 +16,47 @@ use hg\apidoc\annotation as ApiDoc; * Class StoreProductAttrValueController * @package app\store\controller\store_product_attr_value */ +#[ApiDoc\title('商品属性值')] class StoreProductAttrValueController extends BaseAdminController { - - /** - * @notes 获取商品属性值列表 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 14:10 - */ + #[ + ApiDoc\Title('商品属性值列表'), + ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/lists'), + ApiDoc\Method('GET'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(ref: [Definitions::class, "page"]), + ApiDoc\Query(name: 'product_id', type: 'int', require: true, desc: '商品ID'), + ApiDoc\Query(name: 'store_id', type: 'int', require: true, desc: '门店ID'), + ApiDoc\ResponseSuccess("data", type: "array", children: [ + ['name' => 'count', 'desc' => '总数', 'type' => 'int'], + ['name' => 'page_no', 'desc' => '页码', 'type' => 'int'], + ['name' => 'page_size', 'desc' => '每页数量', 'type' => 'int'], + ['name' => 'extend', 'desc' => '扩展数据', 'type' => 'array'], + ['name' => 'lists', 'desc' => '列表数据', 'type' => 'array', 'children' => [ + ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], + ['name' => 'product_id', 'desc' => '商品ID', 'type' => 'int'], + ['name' => 'stock', 'desc' => '库存', 'type' => 'int'], + ['name' => 'unique', 'desc' => '唯一值', 'type' => 'string'], + ['name' => 'sales', 'desc' => '销量', 'type' => 'int'], + ['name' => 'bar_code', 'desc' => '条码', 'type' => 'string'], + ['name' => 'image', 'desc' => '规格图片', 'type' => 'string'], + ]], + ]), + ] public function lists() { return $this->dataLists(new StoreProductAttrValueLists()); } - - /** - * @notes 添加商品属性值 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 14:10 - */ + #[ + ApiDoc\Title('添加商品属性值'), + ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/add'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ] public function add() { $params = (new StoreProductAttrValueValidate())->post()->goCheck('add'); @@ -48,13 +67,13 @@ class StoreProductAttrValueController extends BaseAdminController return $this->fail(StoreProductAttrValueLogic::getError()); } - - /** - * @notes 编辑商品属性值 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 14:10 - */ + #[ + ApiDoc\Title('编辑商品属性值'), + ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/edit'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ] public function edit() { $params = (new StoreProductAttrValueValidate())->post()->goCheck('edit'); @@ -65,13 +84,13 @@ class StoreProductAttrValueController extends BaseAdminController return $this->fail(StoreProductAttrValueLogic::getError()); } - - /** - * @notes 删除商品属性值 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 14:10 - */ + #[ + ApiDoc\Title('删除商品属性值'), + ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/delete'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ] public function delete() { $params = (new StoreProductAttrValueValidate())->post()->goCheck('delete'); @@ -79,13 +98,14 @@ class StoreProductAttrValueController extends BaseAdminController return $this->success('删除成功', [], 1, 1); } - - /** - * @notes 获取商品属性值详情 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 14:10 - */ + #[ + ApiDoc\Title('获取商品属性值详情'), + ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/detail'), + ApiDoc\Method('GET'), + ApiDoc\Author('中国队长'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ] public function detail() { $params = (new StoreProductAttrValueValidate())->goCheck('detail'); diff --git a/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php b/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php index c0b68ea81..e93380f40 100644 --- a/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php +++ b/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php @@ -3,8 +3,8 @@ namespace app\store\lists\store_product_attr_value; +use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; use app\store\lists\BaseAdminDataLists; -use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\lists\ListsSearchInterface; @@ -26,7 +26,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear public function setSearch(): array { return [ - '=' => ['product_id'], + '=' => ['product_id', 'store_id'], ]; } @@ -42,8 +42,8 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear */ public function lists(): array { - return StoreProductAttrValue::where($this->searchWhere) - ->field(['id', 'product_id']) + return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere) + ->field(['id', 'product_id', 'stock', 'unique', 'sales', 'bar_code']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() @@ -59,7 +59,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear */ public function count(): int { - return StoreProductAttrValue::where($this->searchWhere)->count(); + return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere)->count(); } } From f4e3f1bf43b76aea52e1c0bb55e10ded53efdec8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 5 Jun 2024 11:04:37 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=B4=AD=E7=89=A9=E8=AF=A6=E6=83=85=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E5=8F=8A=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoController.php | 29 +++++++ .../StoreOrderCartInfoLists.php | 66 ++++++++++++++++ .../logic/store_order/StoreOrderLogic.php | 10 +-- app/common/enum/OrderEnum.php | 75 ++++++++++++++----- app/common/model/store_order/StoreOrder.php | 14 +++- 5 files changed, 167 insertions(+), 27 deletions(-) create mode 100644 app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php create mode 100644 app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php new file mode 100644 index 000000000..fd4516519 --- /dev/null +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -0,0 +1,29 @@ +dataLists(new StoreOrderCartInfoLists()); + } + +} \ No newline at end of file diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php new file mode 100644 index 000000000..93387ee20 --- /dev/null +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -0,0 +1,66 @@ + ['oid'], + ]; + } + + + /** + * @notes 获取订单购物详情列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + return StoreOrderCartInfo::where($this->searchWhere) + ->field('cart_info')->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item['cart_info'] = json_decode($item['cart_info'], true); //将json字符串转换为数组,方便使用其中的数据。 + return $item; //返回处理后的数据。 + }) + ->toArray(); + } + + + /** + * @notes 获取订单购物详情数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + return StoreOrderCartInfo::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index e515e6383..83f6aba10 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -90,14 +90,10 @@ class StoreOrderLogic extends BaseLogic */ public static function detail($params): array { - $data= StoreOrder::findOrEmpty($params['id'])->toArray(); + $data= StoreOrder::findOrEmpty($params['id']); if($data){ - $data['_info']=StoreOrderCartInfo::where('oid',$data['id'])->field('cart_info') - ->select()->each(function ($item){ - $item['cart_info']=json_decode($item['cart_info'],true);//将json字符串转换为数组,方便使用其中的数据。 - return $item;//返回处理后的数据。 - }); + $data['status_name']=$data->status_name_Text; } - return $data; + return $data?->toArray(); } } \ No newline at end of file diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 43dceeedd..170738636 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -36,16 +36,36 @@ class OrderEnum * @EXPENDITURE 支出 * @INCOME 收入 */ - const EXPENDITURE =0; - const INCOME =1; - + const EXPENDITURE = 0; + const INCOME = 1; + //-----------------------物流状态-----------------------// /** - * 状态 * @RECEIVED_GOODS 已收货 */ const RECEIVED_GOODS = 2; + /** + * @WAIT_EVALUATION 待评价 + */ + const WAIT_EVALUATION = 3; + /** + * @WAIT_DELIVERY 待发货 + */ + const WAIT_DELIVERY = 0; + /** + * @WAIT_RECEIVING 待收货 + */ + const WAIT_RECEIVING = 1; + /** + * @ALREADY_REFUND 申请退款 + */ + const ALREADY_REFUND = -1; + + /** + * @RETURN_SUCCESS 退款成功 + */ + const RETURN_SUCCESS = -2; /** * 核销 @@ -61,11 +81,11 @@ class OrderEnum * @SUPPLIER 供应链 * @SYSTEM 系统 */ - const USER =0; - const MERCHANT =1; - const PLATFORM =2; - const SUPPLIER =3; - const SYSTEM=4; + const USER = 0; + const MERCHANT = 1; + const PLATFORM = 2; + const SUPPLIER = 3; + const SYSTEM = 4; /** * @notes 获取支付类型 @@ -77,14 +97,14 @@ class OrderEnum public static function getFinancialType($value = true) { $data = [ - self::USER_ORDER_PAY=>'用户订单支付', - 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=>'平台设置', + self::USER_ORDER_PAY => '用户订单支付', + 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 => '平台设置', ]; @@ -94,5 +114,22 @@ class OrderEnum return $data[$value] ?? ''; } - -} \ No newline at end of file + /** + * @notes 获取订单状态类型 + */ + public static function getOrderType($value = true) + { + $data = [ + self::RECEIVED_GOODS => '已收货', + self::WAIT_EVALUATION => '待评价', + self::WAIT_DELIVERY => '待发货', + self::WAIT_RECEIVING => '待收货', + self::RETURN_SUCCESS => '退货成功', + self::ALREADY_REFUND => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } +} diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index cdd968394..14fea056d 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -2,7 +2,8 @@ namespace app\common\model\store_order; - +use app\common\enum\OrderEnum; +use app\common\enum\PayEnum; use app\common\model\BaseModel; use app\common\model\system_store\SystemStore; use think\model\concern\SoftDelete; @@ -24,4 +25,15 @@ class StoreOrder extends BaseModel return $this->hasOne(SystemStore::class, 'id','store_id'); } + public function getPayTypeAttr($value, $data) + { + $status = PayEnum::getPaySceneDesc($value)??''; + return $status; + } + + public function getStatusNameTextAttr($value, $data) + { + $status = OrderEnum::getOrderType($data['status'])??''; + return $status; + } } From ed150ce99b81e605fe5cb0ddef2188228f20b0ca Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 5 Jun 2024 11:37:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E5=90=8D=E7=A7=B0=E5=92=8C=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=97=B6=E9=97=B4=E8=8E=B7=E5=8F=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_order/StoreOrderLists.php | 4 ++++ .../StoreOrderCartInfoLists.php | 13 +++++++++++-- app/admin/logic/store_order/StoreOrderLogic.php | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 4f3bde68d..95e5caef8 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -4,6 +4,7 @@ namespace app\admin\lists\store_order; use app\admin\lists\BaseAdminDataLists; +use app\common\enum\OrderEnum; use app\common\enum\PayEnum; use app\common\model\store_order\StoreOrder; use app\common\lists\ListsSearchInterface; @@ -52,6 +53,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface ->order(['id' => 'desc']) ->select()->each(function($item){ $item['pay_type_name']=PayEnum::getPaySceneDesc($item['pay_type']); + $item['pay_time']=$item['pay_time']>0?date('Y-m-d H:i:s',$item['pay_time']):''; + $item['status_name']= OrderEnum::getOrderType($item['status'])??''; + return $item; }) ->toArray(); diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index 93387ee20..71442bf21 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -6,7 +6,9 @@ namespace app\admin\lists\store_order_cart_info; use app\admin\lists\BaseAdminDataLists; use app\common\enum\PayEnum; 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\store_product\StoreProduct; /** * 订单购物详情列表 @@ -43,10 +45,17 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('cart_info')->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) + ->field('cart_info,product_id')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { $item['cart_info'] = json_decode($item['cart_info'], true); //将json字符串转换为数组,方便使用其中的数据。 + $find=StoreBranchProduct::where('id',$item['product_id'])->field('image,store_name')->find(); + if($find){ + $item['image']=$find['image'];//商品图片 + $item['store_name']=$find['store_name'];//商品名称 + }else{ + $item['image']='';//商品图片 + $item['store_name']='';//商品名称 + } return $item; //返回处理后的数据。 }) ->toArray(); diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 83f6aba10..23379ef93 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -92,7 +92,8 @@ class StoreOrderLogic extends BaseLogic { $data= StoreOrder::findOrEmpty($params['id']); if($data){ - $data['status_name']=$data->status_name_Text; + $data['status_name']=$data->status_name_text; + $data['pay_time']=date('Y-m-d H:i:s',$data['pay_time']); } return $data?->toArray(); } From fe5a0db3f0ab976d108fe015608d72bafb04b2af Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 5 Jun 2024 11:39:31 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/functions.php | 39 ++++++++++++++++++- .../store_product/StoreProductController.php | 25 +++++++----- .../StoreBranchProductLogic.php | 31 ++++++++++++--- .../store_product/StoreProductValidate.php | 4 +- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/app/functions.php b/app/functions.php index 458648688..7a23401f1 100644 --- a/app/functions.php +++ b/app/functions.php @@ -340,7 +340,7 @@ if (!function_exists('setUnique')) { { return substr(md5($sku . $id), 12, 11) . $type; } - + } @@ -379,5 +379,42 @@ if (!function_exists('haversineDistance')) { } } +if (!function_exists('reset_index')) { + /** + * 重置数组索引 + * @param array $data + * @param string $index + * @return array + */ + function reset_index(array $data, string $index) + { + $return = []; + foreach ($data as $item) { + $return[$item[$index]] = $item; + } + return $return; + } +} +if (!function_exists('append_to_array')) { + /** + * 追加元素到数组 + * @param array $data + * @param array $append + * @return array + */ + function append_to_array(array $data, array $append) + { + $return = []; + foreach ($data as $item) { + if (isset($append['relation'])) { + $item[$append['value']] = $append['relation'][$item[$append['field']]]; + } else { + $item[$append['value']] = $item[$append['field']]; + } + $return[] = $item; + } + return $return; + } +} diff --git a/app/store/controller/store_product/StoreProductController.php b/app/store/controller/store_product/StoreProductController.php index 74482cce1..ccf7ea746 100644 --- a/app/store/controller/store_product/StoreProductController.php +++ b/app/store/controller/store_product/StoreProductController.php @@ -4,6 +4,7 @@ namespace app\store\controller\store_product; use app\admin\lists\store_branch_product\StoreBranchProductLists; +use app\common\controller\Definitions; use app\store\controller\BaseAdminController; use app\store\logic\store_branch_product\StoreBranchProductLogic; use app\store\logic\store_product\StoreProductLogic; @@ -28,7 +29,8 @@ class StoreProductController extends BaseAdminController ApiDoc\Query(name: 'cate_id', type: 'int', require: false, desc: '分类id'), ApiDoc\Query(name: 'store_name', type: 'string', require: false, desc: '商品名称'), ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态:1上架,2下架,3售罄,4库存告警'), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(ref: [Definitions::class, "page"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], ['name' => 'image', 'desc' => '图片', 'type' => 'string'], @@ -52,7 +54,7 @@ class StoreProductController extends BaseAdminController ApiDoc\url('/store/store_product/storeProduct/add'), ApiDoc\Method('POST'), ApiDoc\NotHeaders(), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], ['name' => 'image', 'desc' => '图片', 'type' => 'string'], @@ -81,7 +83,7 @@ class StoreProductController extends BaseAdminController ApiDoc\Method('POST'), ApiDoc\NotHeaders(), ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], ['name' => 'image', 'desc' => '图片', 'type' => 'string'], @@ -110,7 +112,7 @@ class StoreProductController extends BaseAdminController ApiDoc\Method('POST'), ApiDoc\NotHeaders(), ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], ['name' => 'image', 'desc' => '图片', 'type' => 'string'], @@ -136,7 +138,7 @@ class StoreProductController extends BaseAdminController ApiDoc\Method('GET'), ApiDoc\NotHeaders(), ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], ['name' => 'image', 'desc' => '图片', 'type' => 'string'], @@ -162,7 +164,7 @@ class StoreProductController extends BaseAdminController ApiDoc\Method('POST'), ApiDoc\NotHeaders(), ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array"), ] public function status() @@ -176,16 +178,19 @@ class StoreProductController extends BaseAdminController ApiDoc\Title('商品库存增减'), ApiDoc\url('/store/store_product/storeProduct/stock'), ApiDoc\Method('POST'), - ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"), - ApiDoc\Param(name: "type", type: "int", require: true, desc: "类型:1增加,2减少"), - ApiDoc\Param(name: "number", type: "int", require: true, desc: "数量"), + ApiDoc\Param(name: "attrs", type: "array", require: true, desc: "id", children: [ + ['name' => 'unique', 'desc' => '唯一值', 'type' => 'string'], + ['name' => 'type', 'desc' => '类型:1增加,2减少', 'type' => 'int'], + ['name' => 'number', 'desc' => '数量', 'type' => 'int'], + ]), ApiDoc\NotHeaders(), - ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"), + ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\ResponseSuccess("data", type: "array"), ] public function stock() { $params = (new StoreProductValidate())->post()->goCheck('stock'); + $params['store_id'] = $this->request->adminInfo['store_id']; StoreBranchProductLogic::stock($params); return $this->success('操作成功', [], 1, 1); } diff --git a/app/store/logic/store_branch_product/StoreBranchProductLogic.php b/app/store/logic/store_branch_product/StoreBranchProductLogic.php index 8e7f63c4c..ad7a331ce 100644 --- a/app/store/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/store/logic/store_branch_product/StoreBranchProductLogic.php @@ -4,6 +4,7 @@ namespace app\store\logic\store_branch_product; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; use app\common\model\store_category\StoreCategory; @@ -178,25 +179,43 @@ class StoreBranchProductLogic extends BaseLogic */ public static function stock(array $params): bool { - $StoreProduct = StoreBranchProduct::where('id', $params['id'])->find(); + $attrs = reset_index($params['attrs'], 'unique'); + $attrValue = StoreBranchProductAttrValue::where('store_id', $params['store_id'])->whereIn('unique', array_keys($attrs))->select()->toArray(); + if (empty($attrValue)) { + throw new \Exception('商品属性不存在'); + } + $StoreProduct = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $attrValue[0]['product_id'])->find(); + if (empty($StoreProduct)) { + throw new \Exception('商品不存在'); + } self::checkAuth($StoreProduct); Db::startTrans(); try { - $stock = $params['type'] == 1 ? $StoreProduct['stock'] + $params['number'] : $StoreProduct['stock'] - $params['number']; - $stock = max($stock, 0); - StoreBranchProduct::where('id', $params['id'])->update(['stock' => $stock]); + $productStockIn = 0; + foreach ($attrValue as $k => $v) { + $current = $attrs[$v['unique']] ?? []; + if (empty($current) || $v['unique'] != $current['unique']) { + continue; + } + $stock = $current['type'] == 1 ? $v['stock'] + $current['number'] : $v['stock'] - $current['number']; + $stock = max($stock, 0); + $productStockIn = $current['type'] == 1 ? $StoreProduct['stock'] + $current['number'] : $StoreProduct['stock'] - $current['number']; + $productStockIn = max($productStockIn, 0); + StoreBranchProductAttrValue::where('id', $v['id'])->update(['stock' => $stock]); + } + StoreBranchProduct::where('id', $StoreProduct['id'])->update(['stock' => $productStockIn]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); - throw new BusinessException($e->getMessage()); + throw new \Exception($e->getMessage()); } } public static function checkAuth($product) { if (request()->adminInfo['store_id'] != $product['store_id']) { - throw new BusinessException('没有权限操作'); + throw new \Exception('没有权限操作'); } } diff --git a/app/store/validate/store_product/StoreProductValidate.php b/app/store/validate/store_product/StoreProductValidate.php index b01017d74..f56e1dff3 100644 --- a/app/store/validate/store_product/StoreProductValidate.php +++ b/app/store/validate/store_product/StoreProductValidate.php @@ -21,6 +21,7 @@ class StoreProductValidate extends BaseValidate protected $rule = [ 'id' => 'require', 'store_name' => 'require', + 'attrs' => 'require', ]; @@ -31,6 +32,7 @@ class StoreProductValidate extends BaseValidate protected $field = [ 'id' => 'id', 'store_name' => '商品名称', + 'attrs' => '商品名称', ]; @@ -89,7 +91,7 @@ class StoreProductValidate extends BaseValidate */ public function sceneStock() { - return $this->only(['id', 'type', 'number']); + return $this->only(['attrs']); } } From e373631ff390990ed9825f4e41ebeac8d1a14dc0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 5 Jun 2024 12:36:59 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E5=99=A8=E5=92=8CAPI=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=92=8C=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ExceptionHandler.php | 2 +- app/api/controller/IndexController.php | 88 ++++++++++++++------ app/common/service/wechat/WechatTemplate.php | 2 +- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php index 283ba1719..8cfa3719a 100644 --- a/app/ExceptionHandler.php +++ b/app/ExceptionHandler.php @@ -37,6 +37,6 @@ class ExceptionHandler extends Handler return response(json_encode($error, JSON_UNESCAPED_UNICODE)); } // 非json请求则返回一个页面 - return new Response(200, [], $exception->getMessage()); + return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile()); } } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 6ffbd56a1..2cb6a7358 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -5,24 +5,60 @@ namespace app\api\controller; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; use app\common\logic\store_order\StoreOrderLogic; +use app\common\service\pay\PayService; +use app\common\service\wechat\WechatTemplate; +use Exception; use think\facade\Db; use Webman\Config; use hg\apidoc\annotation as ApiDoc; +use Yansongda\Pay\Exception\InvalidSignException; + #[ApiDoc\NotParse()] class IndexController extends BaseApiController { - public $notNeedLogin = ['index','app_update','express_list','province','city','area','street']; + public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street']; public function index() { + try{ + $a=new WechatTemplate(); + $a->NewQuotationNotification(['openid'=>'ocqhF6UfFQXE-SbzbP5YVQJlQAh0','data1'=>'阿萨','data2'=>date('Y-m-d H:i:s'),'data3'=>'占山','data3'=>18982406440]); + }catch (Exception $e){ + d($e); + } - d(2); - $params=['store_id'=>2,'pay_type'=>17]; - $a=StoreOrderLogic::createOrder([1],0,null,$params); +d(22); + $auth_code = $this->request->get('code'); + $pay = (new PayService()); + $order = [ + 'description' => '条码商品', + 'out_trade_no' => (string)time(), + 'payer' => [ + 'auth_code' => (string)$auth_code + ], + 'amount' => [ + 'total' =>1, + ], + 'scene_info' => [ + "store_info" => [ + 'id' => '1' + ] + ], + ]; + + try{ + $a= $pay->wechat->pos($order); + + }catch (\Exception $th) { + d($th); + } +d($a); + $params = ['store_id' => 2, 'pay_type' => 17]; + $a = StoreOrderLogic::createOrder([1], 0, null, $params); d($a); - return json(['msg' =>create_password(123456, '11d3')]); + return json(['msg' => create_password(123456, '11d3')]); } /** @@ -41,42 +77,46 @@ class IndexController extends BaseApiController /** * @notes 获取app更新信息 */ - public function app_update(){ - $find= Db::name('app_update')->where('type',2)->order('id','desc')->findOrEmpty(); - return $this->success('ok',$find); + public function app_update() + { + $find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty(); + return $this->success('ok', $find); } /** * @notes 获取省列表 */ - public function province(){ - $list= Db::name('geo_province')->select()->toArray(); - return $this->success('ok',$list); + public function province() + { + $list = Db::name('geo_province')->select()->toArray(); + return $this->success('ok', $list); } /** * @notes 获取市列表 */ - public function city(){ - $province_code=$this->request->get('code'); - $list= Db::name('geo_city')->where('province_code',$province_code)->select()?->toArray(); - return $this->success('ok',$list); + public function city() + { + $province_code = $this->request->get('code'); + $list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray(); + return $this->success('ok', $list); } /** * @notes 获取区列表 */ - public function area(){ - $city_code=$this->request->get('code'); - $list= Db::name('geo_area')->where('city_code',$city_code)->select()?->toArray(); - return $this->success('ok',$list); + public function area() + { + $city_code = $this->request->get('code'); + $list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray(); + return $this->success('ok', $list); } /** * @notes 获取街道列表 */ - public function street(){ - $area_code=$this->request->get('area_code'); - $list= Db::name('geo_street')->where('area_code',$area_code)->select()?->toArray(); - return $this->success('ok',$list); + public function street() + { + $area_code = $this->request->get('area_code'); + $list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray(); + return $this->success('ok', $list); } - } diff --git a/app/common/service/wechat/WechatTemplate.php b/app/common/service/wechat/WechatTemplate.php index 52d6c660c..bff36b478 100644 --- a/app/common/service/wechat/WechatTemplate.php +++ b/app/common/service/wechat/WechatTemplate.php @@ -49,7 +49,7 @@ class WechatTemplate 'data' => [ 'thing2' => ['value' => $data['data1']], 'thing3' => ['value' => $data['data2']], - 'const4' => ['value' => $data['data3']??08302669767], + 'const4' => ['value' => $data['data3']??'08302669767'], ] ]; return $this->post($template);