From c47567239bbd2827f1a5f02da6df9b9f9a5d67d8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 29 Apr 2024 16:36:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/OpurchaseclassController.php | 30 ++++- .../supplier/SupplierController.php | 19 ++- app/admin/lists/goods/GoodsLists.php | 2 +- app/admin/lists/retail/CashierclassLists.php | 4 +- app/admin/lists/supplier/SupplierLists.php | 10 +- app/admin/lists/user/UserLists.php | 2 +- app/admin/logic/goods/GoodsLogic.php | 4 - .../logic/operation/OpurchaseclassLogic.php | 80 ++++++++++-- app/admin/logic/order/CartLogic.php | 8 +- app/admin/logic/retail/CashierclassLogic.php | 10 +- app/admin/logic/supplier/SupplierLogic.php | 119 +++++++++++------- .../validate/retail/CashierclassValidate.php | 8 +- .../validate/supplier/SupplierValidate.php | 32 +++-- app/api/controller/LoginController.php | 50 +++++++- app/api/controller/goods/GoodsController.php | 17 +++ .../controller/goods/GoodsclassController.php | 29 +++++ .../merchant/MerchantController.php | 15 +++ .../operation/OpurchaseclassController.php | 32 +++++ app/api/controller/order/CartController.php | 45 ++++++- .../order/RetailOrderController.php | 65 ++++++++++ app/api/controller/user/AddressController.php | 77 ++++++++++++ app/api/lists/BaseApiDataLists.php | 24 ++++ app/api/lists/goods/GoodsLists.php | 114 +++++++++++++++++ app/api/lists/goods/GoodsclassLists.php | 67 ++++++++++ app/api/lists/merchant/MerchantLists.php | 62 +++++++++ .../operation/OpurchaseGoodsOfferList.php | 61 +++++++++ app/api/lists/order/CartList.php | 81 ++++++++++++ app/api/lists/order/RetailOrderList.php | 63 ++++++++++ app/api/lists/user/UserAddressList.php | 62 +++++++++ .../operation/OpurchaseGoodsOfferLogic.php | 8 ++ app/api/logic/order/OrderLogic.php | 80 ++++++------ app/api/logic/user/AddressLogic.php | 96 ++++++++++++++ app/api/validate/UserAddressValidate.php | 91 ++++++++++++++ app/api/validate/WechatLoginValidate.php | 96 ++++++++++++++ app/common/cache/UserTokenCache.php | 3 + app/common/logic/order/RetailOrderLogic.php | 39 ++++-- app/common/model/goods/Goods.php | 2 +- app/common/model/merchat/Merchant.php | 1 + .../model/opurchase/OpurchaseGoodsOffer.php | 22 ++++ app/common/model/opurchase/Opurchaseinfo.php | 3 - app/common/model/user/UserAddress.php | 22 ++++ app/common/service/FileService.php | 2 +- app/common/service/UploadService.php | 5 +- app/common/service/storage/engine/Aliyun.php | 2 +- 44 files changed, 1511 insertions(+), 153 deletions(-) create mode 100644 app/api/controller/goods/GoodsController.php create mode 100644 app/api/controller/goods/GoodsclassController.php create mode 100644 app/api/controller/merchant/MerchantController.php create mode 100644 app/api/controller/operation/OpurchaseclassController.php create mode 100644 app/api/controller/user/AddressController.php create mode 100644 app/api/lists/BaseApiDataLists.php create mode 100644 app/api/lists/goods/GoodsLists.php create mode 100644 app/api/lists/goods/GoodsclassLists.php create mode 100644 app/api/lists/merchant/MerchantLists.php create mode 100644 app/api/lists/operation/OpurchaseGoodsOfferList.php create mode 100644 app/api/lists/order/CartList.php create mode 100644 app/api/lists/order/RetailOrderList.php create mode 100644 app/api/lists/user/UserAddressList.php create mode 100644 app/api/logic/operation/OpurchaseGoodsOfferLogic.php create mode 100644 app/api/logic/user/AddressLogic.php create mode 100644 app/api/validate/UserAddressValidate.php create mode 100644 app/api/validate/WechatLoginValidate.php create mode 100644 app/common/model/opurchase/OpurchaseGoodsOffer.php create mode 100644 app/common/model/user/UserAddress.php diff --git a/app/admin/controller/operation/OpurchaseclassController.php b/app/admin/controller/operation/OpurchaseclassController.php index fb0686f..5f559f8 100644 --- a/app/admin/controller/operation/OpurchaseclassController.php +++ b/app/admin/controller/operation/OpurchaseclassController.php @@ -7,7 +7,7 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\operation\OpurchaseclassLists; use app\admin\logic\operation\OpurchaseclassLogic; use app\admin\validate\operation\OpurchaseclassValidate; - +use app\common\model\opurchase\OpurchaseGoodsOffer; /** * 采购订单控制器 @@ -91,5 +91,33 @@ class OpurchaseclassController extends BaseAdminController return $this->data($result); } + /** + * @notes 推送给供应商报价 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function createSupplierGoods(){ + $params=$this->request->post(); + $result = OpurchaseclassLogic::createSupplierGoods($params); + if (true === $result) { + return $this->success('推送成功', [], 1, 1); + } + return $this->fail(OpurchaseclassLogic::getError()); + } + /** + * @notes 设置采纳商品 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function goods_offer_update(){ + $id=$this->request->post('id'); + $result = OpurchaseclassLogic::goodsOfferUpdate($id); + if ($result) { + return $this->success('已采纳', [], 1, 1); + } + return $this->fail(OpurchaseclassLogic::getError()); + } } \ No newline at end of file diff --git a/app/admin/controller/supplier/SupplierController.php b/app/admin/controller/supplier/SupplierController.php index fcadf11..5ff026c 100644 --- a/app/admin/controller/supplier/SupplierController.php +++ b/app/admin/controller/supplier/SupplierController.php @@ -22,7 +22,7 @@ class SupplierController extends BaseAdminController * @notes 获取供应商管理列表 * @return \think\response\Json * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function lists() { @@ -34,7 +34,7 @@ class SupplierController extends BaseAdminController * @notes 添加供应商管理 * @return \think\response\Json * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function add() { @@ -51,7 +51,7 @@ class SupplierController extends BaseAdminController * @notes 编辑供应商管理 * @return \think\response\Json * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function edit() { @@ -68,7 +68,7 @@ class SupplierController extends BaseAdminController * @notes 删除供应商管理 * @return \think\response\Json * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function delete() { @@ -82,7 +82,7 @@ class SupplierController extends BaseAdminController * @notes 获取供应商管理详情 * @return \think\response\Json * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function detail() { @@ -91,5 +91,12 @@ class SupplierController extends BaseAdminController return $this->data($result); } - + public function setLabel(){ + $params=$this->request->post(); + $result = SupplierLogic::setLabel($params); + if (true === $result) { + return $this->success('设置成功', [], 1, 1); + } + return $this->fail(SupplierLogic::getError()); + } } \ No newline at end of file diff --git a/app/admin/lists/goods/GoodsLists.php b/app/admin/lists/goods/GoodsLists.php index 0c36f8f..dac26f3 100644 --- a/app/admin/lists/goods/GoodsLists.php +++ b/app/admin/lists/goods/GoodsLists.php @@ -26,7 +26,7 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'class', 'brand', 'unit', 'code', 'warehouse', 'retail_name', 'sort'], + '=' => ['name', 'class', 'brand', 'unit', 'code', 'warehouse', 'sort'], ]; } diff --git a/app/admin/lists/retail/CashierclassLists.php b/app/admin/lists/retail/CashierclassLists.php index 0e2de88..0598a6e 100644 --- a/app/admin/lists/retail/CashierclassLists.php +++ b/app/admin/lists/retail/CashierclassLists.php @@ -26,7 +26,7 @@ class CashierclassLists extends BaseAdminDataLists implements ListsSearchInterfa public function setSearch(): array { $search= [ - '=' => ['merchant', 'store_id', 'customer', 'time', 'number', 'user', 'pay_type', 'type', 'auditinguser'], + '=' => ['merchant', 'store_id', 'number', 'user', 'pay_type', 'type', 'auditinguser'], ]; return $search; } @@ -49,7 +49,7 @@ class CashierclassLists extends BaseAdminDataLists implements ListsSearchInterfa public function lists(): array { return Cashierclass::where($this->searchWhere) - ->field(['id', 'merchant', 'store_id', 'customer', 'time', 'number', 'total', 'deduction_price', 'actual', 'money', 'user', 'pay_type', 'type', 'auditinguser', 'auditingtime']) + ->field(['id', 'merchant', 'store_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'user', 'pay_type', 'type', 'auditinguser', 'auditingtime']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() diff --git a/app/admin/lists/supplier/SupplierLists.php b/app/admin/lists/supplier/SupplierLists.php index f674927..f67481f 100644 --- a/app/admin/lists/supplier/SupplierLists.php +++ b/app/admin/lists/supplier/SupplierLists.php @@ -21,12 +21,12 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface * @notes 设置搜索条件 * @return \string[][] * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function setSearch(): array { return [ - '=' => ['name', 'tel', 'supplier_type', 'invoice_type'], + '=' => ['category_id', 'type_id', 'mer_name'], ]; } @@ -38,12 +38,12 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function lists(): array { return Supplier::where($this->searchWhere) - ->field(['id', 'name', 'py', 'number', 'uid', 'contacts', 'tel', 'bank', 'account', 'tax', 'supplier_type', 'tax_rate', 'invoice_type', 'dept_type']) + ->field(['id', 'category_id', 'type_id', 'mer_name', 'settle_cycle', 'interest_rate', 'sys_labels', 'mer_address', 'status', 'commission_rate', 'commission_switch', 'mer_money']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() @@ -55,7 +55,7 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface * @notes 获取供应商管理数量 * @return int * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function count(): int { diff --git a/app/admin/lists/user/UserLists.php b/app/admin/lists/user/UserLists.php index 688ef6f..69f9cb6 100644 --- a/app/admin/lists/user/UserLists.php +++ b/app/admin/lists/user/UserLists.php @@ -35,7 +35,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function lists(): array { - $field = "id,sn,nickname,sex,avatar,account,mobile,channel,create_time"; + $field = "id,nickname,sex,avatar,account,mobile,channel,create_time"; $lists = User::withSearch($this->setSearch(), $this->params) ->limit($this->limitOffset, $this->limitLength) ->field($field) diff --git a/app/admin/logic/goods/GoodsLogic.php b/app/admin/logic/goods/GoodsLogic.php index 9b8a2db..301478f 100644 --- a/app/admin/logic/goods/GoodsLogic.php +++ b/app/admin/logic/goods/GoodsLogic.php @@ -39,12 +39,10 @@ class GoodsLogic extends BaseLogic 'buy' => $params['buy'], 'sell' => $params['sell'], 'retail' => $params['retail'], - 'integral' => $params['integral'], 'code' => $params['code'], 'warehouse' => $params['warehouse'], 'location' => $params['location'], 'stocktip' => $params['stocktip'], - 'retail_name' => $params['retail_name'], 'imgs' => $params['imgs'], 'details' => $params['details'] ? implode(',', $params['details']) : '', 'data' => $params['data'], @@ -84,12 +82,10 @@ class GoodsLogic extends BaseLogic 'buy' => $params['buy'], 'sell' => $params['sell'], 'retail' => $params['retail'], - 'integral' => $params['integral'], 'code' => $params['code'], 'warehouse' => $params['warehouse'], 'location' => $params['location'], 'stocktip' => $params['stocktip'], - 'retail_name' => $params['retail_name'], 'imgs' => $params['imgs'], 'details' => $params['details'] ? implode(',', $params['details']) : '', 'data' => $params['data'], diff --git a/app/admin/logic/operation/OpurchaseclassLogic.php b/app/admin/logic/operation/OpurchaseclassLogic.php index b234ce2..bcf7f63 100644 --- a/app/admin/logic/operation/OpurchaseclassLogic.php +++ b/app/admin/logic/operation/OpurchaseclassLogic.php @@ -5,6 +5,10 @@ namespace app\admin\logic\operation; use app\common\model\operation\Opurchaseclass; use app\common\logic\BaseLogic; +use app\common\model\goods\Goods; +use app\common\model\opurchase\OpurchaseGoodsOffer; +use app\common\model\opurchase\Opurchaseinfo; +use app\common\model\supplier\Supplier; use think\facade\Db; @@ -28,9 +32,7 @@ class OpurchaseclassLogic extends BaseLogic { Db::startTrans(); try { - Opurchaseclass::create([ - - ]); + Opurchaseclass::create([]); Db::commit(); return true; @@ -53,9 +55,7 @@ class OpurchaseclassLogic extends BaseLogic { Db::startTrans(); try { - Opurchaseclass::where('id', $params['id'])->update([ - - ]); + Opurchaseclass::where('id', $params['id'])->update([]); Db::commit(); return true; @@ -89,6 +89,70 @@ class OpurchaseclassLogic extends BaseLogic */ public static function detail($params): array { - return Opurchaseclass::findOrEmpty($params['id'])->toArray(); + $data = Opurchaseclass::findOrEmpty($params['id'])->toArray(); + if ($data) { + $data['info'] = Opurchaseinfo::where('pid', $params['id'])->select()->each(function ($item) { + $sys_labels = Goods::where('id', $item['goods'])->value('sys_labels'); + $supplier_arr=[]; + if($sys_labels){ + $arr = explode(',', $sys_labels); + foreach ($arr as $k => $v) { + if($v>0){ + $supplier=Supplier::whereLike('sys_labels', "%," . $v . ",%")->field('id,mer_name')->find(); + if($supplier){ + $supplier_arr[]=$supplier; + } + } + } + } + $item['supplier'] = array_unique($supplier_arr); + + }); + } + return $data; } -} \ No newline at end of file + + /** + * @notes 推送供应商商品 + * @param $params + * @return bool + * @date 2024/04/27 11:26 + */ + public static function createSupplierGoods($params){ + try{ + $goods_offer=[]; + foreach($params['goods_info'] as $k=>$v){ + $goods_offer[]=[ + 'supplier_id'=>$v['supplier'], + 'goods_id'=>$v['goods'], + 'price'=>0, + ]; + } + if($goods_offer){ + $res=OpurchaseGoodsOffer::insertAll($goods_offer); + if($res){ + return true; + } + } + }catch (\Exception $e){ + self::setError($e->getMessage()); + return false; + } + } + + /** + * @notes 设置采纳商品 + * @param $params + * @return bool + * @date 2024/04/27 11:26 + */ + public static function goodsOfferUpdate($params){ + try{ + OpurchaseGoodsOffer::where('id',$params)->update(['is_adopt'=>1]); + return true; + }catch (\Exception $e){ + self::setError($e->getMessage()); + return false; + } + } +} diff --git a/app/admin/logic/order/CartLogic.php b/app/admin/logic/order/CartLogic.php index 55c2ef2..f14804c 100644 --- a/app/admin/logic/order/CartLogic.php +++ b/app/admin/logic/order/CartLogic.php @@ -54,11 +54,15 @@ class CartLogic extends BaseLogic * @author likeadmin * @date 2024/04/24 10:37 */ - public static function edit(array $params): bool + public static function edit(array $params,$type='inc'): bool { Db::startTrans(); try { - Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->inc('cart_num',$params['cart_num'])->update(); + if($type=='inc'){ + Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->inc('cart_num',$params['cart_num'])->update(); + }else{ + Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->dec('cart_num',$params['cart_num'])->update(); + } Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/admin/logic/retail/CashierclassLogic.php b/app/admin/logic/retail/CashierclassLogic.php index 0931e2c..90d0b31 100644 --- a/app/admin/logic/retail/CashierclassLogic.php +++ b/app/admin/logic/retail/CashierclassLogic.php @@ -31,8 +31,7 @@ class CashierclassLogic extends BaseLogic Cashierclass::create([ 'merchant' => $params['merchant'], 'store_id' => $params['store_id'], - 'customer' => $params['customer'], - 'time' => $params['time'], + 'uid' => $params['uid'], 'number' => $params['number'], 'total' => $params['total'], 'deduction_price' => $params['deduction_price'], @@ -41,8 +40,6 @@ class CashierclassLogic extends BaseLogic 'pay_type' => $params['pay_type'], 'data' => $params['data'], 'type' => $params['type'], - 'auditinguser' => $params['auditinguser'], - 'auditingtime' => strtotime($params['auditingtime']), 'more' => $params['more'] ]); @@ -70,8 +67,7 @@ class CashierclassLogic extends BaseLogic Cashierclass::where('id', $params['id'])->update([ 'merchant' => $params['merchant'], 'store_id' => $params['store_id'], - 'customer' => $params['customer'], - 'time' => $params['time'], + 'uid' => $params['uid'], 'number' => $params['number'], 'total' => $params['total'], 'deduction_price' => $params['deduction_price'], @@ -80,8 +76,6 @@ class CashierclassLogic extends BaseLogic 'pay_type' => $params['pay_type'], 'data' => $params['data'], 'type' => $params['type'], - 'auditinguser' => $params['auditinguser'], - 'auditingtime' => strtotime($params['auditingtime']), 'more' => $params['more'] ]); diff --git a/app/admin/logic/supplier/SupplierLogic.php b/app/admin/logic/supplier/SupplierLogic.php index e11605e..7ddfec2 100644 --- a/app/admin/logic/supplier/SupplierLogic.php +++ b/app/admin/logic/supplier/SupplierLogic.php @@ -22,32 +22,37 @@ class SupplierLogic extends BaseLogic * @param array $params * @return bool * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public static function add(array $params): bool { Db::startTrans(); try { Supplier::create([ - 'name' => $params['name'], - 'py' => $params['py'], - 'number' => $params['number'], - 'uid' => $params['uid'], - 'contacts' => $params['contacts'], - 'tel' => $params['tel'], - 'add' => $params['add'], - 'bank' => $params['bank'], - 'account' => $params['account'], - 'tax' => $params['tax'], - 'other' => $params['other'], - 'email' => $params['email'], - 'data' => $params['data'], - 'more' => $params['more'], - 'supplier_type' => $params['supplier_type'], - 'tax_rate' => $params['tax_rate'], - 'invoice_type' => $params['invoice_type'], - 'dept_type' => $params['dept_type'], - 'sort' => $params['sort'] + 'category_id' => $params['category_id'], + 'type_id' => $params['type_id'], + 'mer_name' => $params['mer_name'], + 'settle_cycle' => $params['settle_cycle'], + 'interest_rate' => $params['interest_rate'], + 'sys_labels' => $params['sys_labels'], + 'city_id' => $params['city_id'], + 'area_id' => $params['area_id'], + 'street_id' => $params['street_id'], + 'village_id' => $params['village_id'], + 'mer_address' => $params['mer_address'], + 'mer_avatar' => $params['mer_avatar'], + 'mark' => $params['mark'], + 'status' => $params['status'], + 'commission_rate' => $params['commission_rate'], + 'commission_switch' => $params['commission_switch'], + 'long' => $params['long'], + 'lat' => $params['lat'], + 'service_phone' => $params['service_phone'], + 'mer_money' => $params['mer_money'], + 'financial_bank' => $params['financial_bank'], + 'financial_wechat' => $params['financial_wechat'], + 'financial_alipay' => $params['financial_alipay'], + 'financial_type' => $params['financial_type'] ]); Db::commit(); @@ -65,32 +70,37 @@ class SupplierLogic extends BaseLogic * @param array $params * @return bool * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public static function edit(array $params): bool { Db::startTrans(); try { Supplier::where('id', $params['id'])->update([ - 'name' => $params['name'], - 'py' => $params['py'], - 'number' => $params['number'], - 'uid' => $params['uid'], - 'contacts' => $params['contacts'], - 'tel' => $params['tel'], - 'add' => $params['add'], - 'bank' => $params['bank'], - 'account' => $params['account'], - 'tax' => $params['tax'], - 'other' => $params['other'], - 'email' => $params['email'], - 'data' => $params['data'], - 'more' => $params['more'], - 'supplier_type' => $params['supplier_type'], - 'tax_rate' => $params['tax_rate'], - 'invoice_type' => $params['invoice_type'], - 'dept_type' => $params['dept_type'], - 'sort' => $params['sort'] + 'category_id' => $params['category_id'], + 'type_id' => $params['type_id'], + 'mer_name' => $params['mer_name'], + 'settle_cycle' => $params['settle_cycle'], + 'interest_rate' => $params['interest_rate'], + 'sys_labels' => $params['sys_labels'], + 'city_id' => $params['city_id'], + 'area_id' => $params['area_id'], + 'street_id' => $params['street_id'], + 'village_id' => $params['village_id'], + 'mer_address' => $params['mer_address'], + 'mer_avatar' => $params['mer_avatar'], + 'mark' => $params['mark'], + 'status' => $params['status'], + 'commission_rate' => $params['commission_rate'], + 'commission_switch' => $params['commission_switch'], + 'long' => $params['long'], + 'lat' => $params['lat'], + 'service_phone' => $params['service_phone'], + 'mer_money' => $params['mer_money'], + 'financial_bank' => $params['financial_bank'], + 'financial_wechat' => $params['financial_wechat'], + 'financial_alipay' => $params['financial_alipay'], + 'financial_type' => $params['financial_type'] ]); Db::commit(); @@ -108,7 +118,7 @@ class SupplierLogic extends BaseLogic * @param array $params * @return bool * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public static function delete(array $params): bool { @@ -121,10 +131,35 @@ class SupplierLogic extends BaseLogic * @param $params * @return array * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public static function detail($params): array { return Supplier::findOrEmpty($params['id'])->toArray(); } + + /** + * @notes 设置标签 + * @param $params + * @return bool + * @date 2024/04/23 11:28 + */ + public static function setLabel($params) + { + try { + $value = $params['sys_labels']; + if (!empty($value)) { + if (!is_array($value)){ + $value= ',' . $value . ','; + }else{ + $value = ',' . implode(',', $value) . ','; + } + } + Supplier::where('id', $params['id'])->update(['sys_labels' => $value]); + return true; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + } } \ No newline at end of file diff --git a/app/admin/validate/retail/CashierclassValidate.php b/app/admin/validate/retail/CashierclassValidate.php index d6c46fd..13943ec 100644 --- a/app/admin/validate/retail/CashierclassValidate.php +++ b/app/admin/validate/retail/CashierclassValidate.php @@ -21,7 +21,7 @@ class CashierclassValidate extends BaseValidate protected $rule = [ 'id' => 'require', 'merchant' => 'require', - 'customer' => 'require', + 'uid' => 'require', 'time' => 'require', 'number' => 'require', 'total' => 'require', @@ -38,7 +38,7 @@ class CashierclassValidate extends BaseValidate protected $field = [ 'id' => 'id', 'merchant' => '所属商户', - 'customer' => '客户ID', + 'uid' => '客户ID', 'time' => '单据时间', 'number' => '单据编号', 'total' => '单据金额', @@ -56,7 +56,7 @@ class CashierclassValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['merchant','customer','time','number','total','actual','money','pay_type']); + return $this->only(['merchant','number','total','actual','money','pay_type']); } @@ -68,7 +68,7 @@ class CashierclassValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','merchant','customer','time','number','total','actual','money','pay_type']); + return $this->only(['id','merchant','number','total','actual','money','pay_type']); } diff --git a/app/admin/validate/supplier/SupplierValidate.php b/app/admin/validate/supplier/SupplierValidate.php index f37ba20..08b52d6 100644 --- a/app/admin/validate/supplier/SupplierValidate.php +++ b/app/admin/validate/supplier/SupplierValidate.php @@ -20,7 +20,15 @@ class SupplierValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', - 'name' => 'require', + 'category_id' => 'require', + 'mer_name' => 'require', + 'settle_cycle' => 'require', + 'interest_rate' => 'require', + 'mer_address' => 'require', + 'mark' => 'require', + 'status' => 'require', + 'service_phone' => 'require', + 'mer_money' => 'require', ]; @@ -30,7 +38,15 @@ class SupplierValidate extends BaseValidate */ protected $field = [ 'id' => 'id', - 'name' => '名称', + 'category_id' => '商户分类 id', + 'mer_name' => '商户名称', + 'settle_cycle' => '结算周期,单位天', + 'interest_rate' => '利率', + 'mer_address' => '商户地址', + 'mark' => '商户备注', + 'status' => '商户是否禁用0锁定,1正常', + 'service_phone' => '店铺电话', + 'mer_money' => '商户余额', ]; @@ -38,11 +54,11 @@ class SupplierValidate extends BaseValidate * @notes 添加场景 * @return SupplierValidate * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function sceneAdd() { - return $this->only(['name']); + return $this->only(['category_id','mer_name','settle_cycle','interest_rate','mer_address','mark','status','service_phone','mer_money']); } @@ -50,11 +66,11 @@ class SupplierValidate extends BaseValidate * @notes 编辑场景 * @return SupplierValidate * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function sceneEdit() { - return $this->only(['id','name']); + return $this->only(['id','category_id','mer_name','settle_cycle','interest_rate','mer_address','mark','status','service_phone','mer_money']); } @@ -62,7 +78,7 @@ class SupplierValidate extends BaseValidate * @notes 删除场景 * @return SupplierValidate * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function sceneDelete() { @@ -74,7 +90,7 @@ class SupplierValidate extends BaseValidate * @notes 详情场景 * @return SupplierValidate * @author likeadmin - * @date 2024/04/23 15:56 + * @date 2024/04/27 14:33 */ public function sceneDetail() { diff --git a/app/api/controller/LoginController.php b/app/api/controller/LoginController.php index 310abd6..39e3892 100644 --- a/app/api/controller/LoginController.php +++ b/app/api/controller/LoginController.php @@ -2,13 +2,16 @@ namespace app\api\controller; -use app\api\validate\LoginAccountValidate; use app\api\logic\LoginLogic; +use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate}; class LoginController extends BaseApiController { - public $notNeedLogin = ['account']; + public $notNeedLogin = ['account','logout']; + /** + * @notes 账号登录 + */ public function account() { $params=$this->request->post(); @@ -19,4 +22,47 @@ class LoginController extends BaseApiController } return $this->data($result); } + /** + * @notes 退出登录 + */ + public function logout() + { + LoginLogic::logout($this->userInfo); + return $this->success(); + } + + + /** + * @notes 小程序-登录接口 + * @return \think\response\Json + * @author 段誉 + * @date 2022/9/20 19:48 + */ + public function mnpLogin() + { + $params = (new WechatLoginValidate())->post()->goCheck('mnpLogin'); + $res = LoginLogic::mnpLogin($params); + if (false === $res) { + return $this->fail(LoginLogic::getError()); + } + return $this->success('', $res); + } + + + /** + * @notes 小程序绑定微信 + * @return \think\response\Json + * @author 段誉 + * @date 2022/9/20 19:48 + */ + public function mnpAuthBind() + { + $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); + } } diff --git a/app/api/controller/goods/GoodsController.php b/app/api/controller/goods/GoodsController.php new file mode 100644 index 0000000..3769157 --- /dev/null +++ b/app/api/controller/goods/GoodsController.php @@ -0,0 +1,17 @@ +dataLists(new GoodsLists()); + } + + +} \ No newline at end of file diff --git a/app/api/controller/goods/GoodsclassController.php b/app/api/controller/goods/GoodsclassController.php new file mode 100644 index 0000000..59c48ba --- /dev/null +++ b/app/api/controller/goods/GoodsclassController.php @@ -0,0 +1,29 @@ +dataLists(new GoodsclassLists()); + } + + +} \ No newline at end of file diff --git a/app/api/controller/merchant/MerchantController.php b/app/api/controller/merchant/MerchantController.php new file mode 100644 index 0000000..ff532bd --- /dev/null +++ b/app/api/controller/merchant/MerchantController.php @@ -0,0 +1,15 @@ +dataLists(new MerchantLists()); + } +} \ No newline at end of file diff --git a/app/api/controller/operation/OpurchaseclassController.php b/app/api/controller/operation/OpurchaseclassController.php new file mode 100644 index 0000000..3944a16 --- /dev/null +++ b/app/api/controller/operation/OpurchaseclassController.php @@ -0,0 +1,32 @@ +dataLists(new OpurchaseGoodsOfferList()); + } + + /** + * 创建报价 + */ + public function create_price(){ + $id=$this->request->post('id'); + $price=$this->request->post('price'); + $nums=$this->request->post('nums'); + $supplier_id=$this->request->userInfo['supplier']['id']; + if(!$supplier_id) return $this->fail('请先绑定供应商'); + $res=OpurchaseGoodsOffer::where('supplier_id',$supplier_id)->where('id',$id)->update(['price'=>$price,'nums'=>$nums]); + if($res) return $this->success('报价成功'); + return $this->fail('报价失败'); + } + +} \ No newline at end of file diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index bd58f8a..d64876e 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -5,14 +5,26 @@ namespace app\api\controller\order; use app\admin\logic\order\CartLogic; use app\admin\validate\order\CartValidate; use app\api\controller\BaseApiController; +use app\api\lists\order\CartList; use app\common\model\order\Cart; class CartController extends BaseApiController { + public function list(){ + return $this->dataLists(new CartList()); + } + + /** + * @notes 添加购物车 + */ public function create(){ - $params = (new CartValidate())->get()->goCheck('add'); - $params['uid']=1; + $params = (new CartValidate())->post()->goCheck('add'); + $params['uid']=$this->request->userId; $result=Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id'],'is_fail'=>0,'is_pay'=>0])->find(); + $count=Cart::where(['uid'=>$params['uid'],'is_fail'=>0,'is_pay'=>0])->count(); + if($count>100){ + return $this->fail('购物车商品不能大于100个,请先结算'); + } if($result){ $res=CartLogic::edit($params); }else{ @@ -25,4 +37,33 @@ class CartController extends BaseApiController } } + /** + * @notes 修改购物车 + */ + public function change(){ + $params = (new CartValidate())->post()->goCheck('change'); + $params['uid']=$this->request->userId; + $res=CartLogic::edit($params,'dec'); + if($res){ + return $this->success('修改成功'); + }else{ + return $this->fail(CartLogic::getError()); + } + } + /** + * @notes 删除购物车 + */ + public function delete(){ + $params = (new CartValidate())->post()->goCheck('delete'); + $params['uid']=$this->request->userId; + $res=CartLogic::delete($params); + if($res){ + return $this->success('删除成功'); + }else{ + return $this->fail(CartLogic::getError()); + } + } + + + } \ No newline at end of file diff --git a/app/api/controller/order/RetailOrderController.php b/app/api/controller/order/RetailOrderController.php index 0391d11..ea42abe 100644 --- a/app/api/controller/order/RetailOrderController.php +++ b/app/api/controller/order/RetailOrderController.php @@ -5,14 +5,26 @@ namespace app\api\controller\order; use app\admin\logic\order\CartLogic; use app\api\logic\order\OrderLogic; use app\api\controller\BaseApiController; +use app\api\lists\order\RetailOrderList; use app\common\logic\order\RetailOrderLogic; use app\common\enum\PayEnum; use app\common\model\order\Cart; +use app\common\model\retail\Cashierclass; use app\common\model\user\User; class RetailOrderController extends BaseApiController { + /** + * 订单列表 + */ + public function order_list(){ + + return $this->dataLists(new RetailOrderList()); + } + /** + * @notes 检测零售订单 + */ public function checkOrder(){ $cartId = (Array)$this->request->post('cart_id', []); $addressId = (int)$this->request->post('address_id'); @@ -20,6 +32,13 @@ class RetailOrderController extends BaseApiController $auth_code = $this->request->post('auth_code'); //微信支付条码 $params=$this->request->post(); $res=OrderLogic::cartIdByOrderInfo($cartId,$addressId,null,$params); + if($res==false){ + $msg=OrderLogic::getError(); + if($msg=='购物车为空'){ + return $this->data([]); + } + return $this->fail(OrderLogic::getError()); + } return $this->data($res); } @@ -30,6 +49,9 @@ class RetailOrderController extends BaseApiController $user=User::where('id',$this->request->userId)->find(); $cartId = (Array)$this->request->post('cart_id', []); + if(count($cartId)>100){ + return $this->fail('购物车商品不能超过100个'); + } $addressId = (int)$this->request->post('address_id'); $pay_type = (int)$this->request->post('pay_type'); $auth_code = $this->request->post('auth_code'); //微信支付条码 @@ -54,4 +76,47 @@ class RetailOrderController extends BaseApiController return $this->fail(OrderLogic::getError()); } } + + /** + * 重新支付 + */ + public function Repayment(){ + $order_id = (int)$this->request->post('order_id'); + $pay_type = (int)$this->request->post('pay_type'); + $where=[ + 'order_id'=>$order_id, + 'uid'=>$this->userId, + 'paid'=>0, + ]; + $order=Cashierclass::where($where)->find(); + if($pay_type==PayEnum::BALANCE_PAY){ + $user=User::where('id',$this->request->userId)->find(); + $res=RetailOrderLogic::payBalance($user,$order); + if($res==true){ + $res=RetailOrderLogic::paySuccess($order, ['money'=>$order['actual']]); + if($res){ + }else{ + return $this->fail(RetailOrderLogic::getError()); + } + }else{ + return $this->fail(RetailOrderLogic::getError()); + } + } + return $this->fail('支付失败'); + + } + + /** + * 获取用户常用购买记录 + */ + public function frequently_purchase(){ + $params=$this->request->get(); + $res=RetailOrderLogic::frequentlyPurchase($params); + if($res==false){ + return $this->fail(RetailOrderLogic::getError()); + }else{ + return $this->data($res); + } + } + } \ No newline at end of file diff --git a/app/api/controller/user/AddressController.php b/app/api/controller/user/AddressController.php new file mode 100644 index 0000000..708ff94 --- /dev/null +++ b/app/api/controller/user/AddressController.php @@ -0,0 +1,77 @@ +dataLists(new UserAddressList()); + } + /** + * @notes 添加地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function create() + { + $params = (new UserAddressValidate())->post()->goCheck('add'); + $params['uid'] = $this->request->userId; + $res=AddressLogic::add($params); + if($res){ + return $this->success('添加成功'); + }else{ + return $this->fail(AddressLogic::getError()); + } + } + /** + * @notes 编辑地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function edit() + { + $params = (new UserAddressValidate())->post()->goCheck('edit'); + $params['uid'] = $this->request->userId; + if(AddressLogic::edit($params)){ + return $this->success('编辑成功'); + }else{ + return $this->fail(AddressLogic::getError()); + } + } + + + /** + * @notes 删除地址 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function delete() + { + $params = (new UserAddressValidate())->post()->goCheck('delete'); + if(AddressLogic::delete($params)){ + return $this->success('删除成功'); + }else{ + return $this->fail(AddressLogic::getError()); + } + } + + /** + * @notes 获取地址详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/4/24 10:37 + */ + public function detail() + { + $params = (new UserAddressValidate())->goCheck('detail'); + return $this->success('获取成功',AddressLogic::detail($params)); + } +} diff --git a/app/api/lists/BaseApiDataLists.php b/app/api/lists/BaseApiDataLists.php new file mode 100644 index 0000000..38d01a3 --- /dev/null +++ b/app/api/lists/BaseApiDataLists.php @@ -0,0 +1,24 @@ +request->userInfo) && $this->request->userInfo) { + $this->userInfo = $this->request->userInfo; + $this->userId = $this->request->userId; + } + $this->export = $this->request->get('export', ''); + } + + +} \ No newline at end of file diff --git a/app/api/lists/goods/GoodsLists.php b/app/api/lists/goods/GoodsLists.php new file mode 100644 index 0000000..bf2fcba --- /dev/null +++ b/app/api/lists/goods/GoodsLists.php @@ -0,0 +1,114 @@ + ['name'], + '=' => ['class'] + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['sell' => 'sell', 'sales' => 'sales',]; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['sales' => 'desc','sell' => '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'); + $where=[]; + if($class_all){ + $arr=[]; + $arr2=[]; + $arr=Goodsclass::where('pid',$class_all)->column('id'); + if($arr){ + $arr2=Goodsclass::where('pid','in',$arr)->column('id'); + $where[]=['class','in',array_merge($arr,$arr2)]; + }else{ + $where[]=['class','=',$class_all]; + } + } + return Goods::where($this->searchWhere)->where($where) + ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs',]) + ->limit($this->limitOffset, $this->limitLength) + ->with(['className','brandName','unitName']) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + $class_all=$this->request->get('class_all'); + $where=[]; + if($class_all){ + $arr=[]; + $arr2=[]; + $arr=Goodsclass::where('pid',$class_all)->column('id'); + if($arr){ + $arr2=Goodsclass::where('pid','in',$arr)->column('id'); + $where[]=['class','in',array_merge($arr,$arr2)]; + }else{ + $where[]=['class','=',$class_all]; + } + } + return Goods::where($this->searchWhere)->where($where)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/goods/GoodsclassLists.php b/app/api/lists/goods/GoodsclassLists.php new file mode 100644 index 0000000..51dee0a --- /dev/null +++ b/app/api/lists/goods/GoodsclassLists.php @@ -0,0 +1,67 @@ + ['pid', 'name', 'data', 'pic', 'sort'], + ]; + } + + + /** + * @notes 获取商品分类列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function lists(): array + { + $lists= Goodsclass::where($this->searchWhere) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + return linear_to_tree($lists, 'children'); + + } + + + /** + * @notes 获取商品分类数量 + * @return int + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function count(): int + { + return Goodsclass::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/merchant/MerchantLists.php b/app/api/lists/merchant/MerchantLists.php new file mode 100644 index 0000000..216bbde --- /dev/null +++ b/app/api/lists/merchant/MerchantLists.php @@ -0,0 +1,62 @@ +searchWhere) + ->field('mer_id,mer_name') + ->limit($this->limitOffset, $this->limitLength) + ->order(['mer_id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 商户数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return OpurchaseGoodsOffer::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/operation/OpurchaseGoodsOfferList.php b/app/api/lists/operation/OpurchaseGoodsOfferList.php new file mode 100644 index 0000000..8a9a69d --- /dev/null +++ b/app/api/lists/operation/OpurchaseGoodsOfferList.php @@ -0,0 +1,61 @@ +request->userInfo['supplier']['id']; + if(!$supplier_id) return []; + return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取采购供应链商户报价数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return OpurchaseGoodsOffer::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php new file mode 100644 index 0000000..359e402 --- /dev/null +++ b/app/api/lists/order/CartList.php @@ -0,0 +1,81 @@ +request->userId; + if (!$userId) return []; + $list = Cart::where($this->searchWhere)->where('uid', $userId) + ->limit($this->limitOffset, $this->limitLength) + ->order(['cart_id' => 'desc']) + ->select()->each(function ($item) { + + return $item; + }) + ->toArray(); + + $total_price = 0; + foreach ($list as $key => &$item) { + $sell = Goods::where('id', $item['goods_id'])->value('sell'); + $item['goods_total_price'] = bcmul($item['cart_num'], $sell, 2); + $total_price += $item['goods_total_price']; + } + $this->total_price=$total_price; + return $list; + } + + + /** + * @notes 购物车数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return Cart::where($this->searchWhere)->count(); + } + + public function extend() + { + return ['total_price'=>$this->total_price]; + } +} diff --git a/app/api/lists/order/RetailOrderList.php b/app/api/lists/order/RetailOrderList.php new file mode 100644 index 0000000..cc26451 --- /dev/null +++ b/app/api/lists/order/RetailOrderList.php @@ -0,0 +1,63 @@ + ['number', 'paid',], + 'between_time' => 'create_time', + ]; + } + + + /** + * @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 []; + return Cashierclass::where($this->searchWhere)->where('uid',$userId) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 零售订单数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return Cashierclass::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/user/UserAddressList.php b/app/api/lists/user/UserAddressList.php new file mode 100644 index 0000000..b7e4b66 --- /dev/null +++ b/app/api/lists/user/UserAddressList.php @@ -0,0 +1,62 @@ +request->userId; + if(!$user_id) return []; + return UserAddress::where($this->searchWhere)->where('uid',$user_id) + ->limit($this->limitOffset, $this->limitLength) + ->order(['address_id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取地址数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + $user_id=$this->request->userId; + return UserAddress::where($this->searchWhere)->where('uid',$user_id)->count(); + } + +} \ No newline at end of file diff --git a/app/api/logic/operation/OpurchaseGoodsOfferLogic.php b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php new file mode 100644 index 0000000..a3016db --- /dev/null +++ b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php @@ -0,0 +1,8 @@ + 0, 'is_fail' => 0]; @@ -33,19 +33,24 @@ class OrderLogic extends BaseLogic self::setError('购物车为空'); return false; } - /** 计算价格 */ - foreach ($cart_select as $k => $v) { - $sell = Goods::where(['id' => $v['goods']])->value('sell'); - $cart_select[$k]['total'] = bcmul($v['cart_num'], $sell, 2); - $cart_select[$k]['price'] = $sell; + try { + /** 计算价格 */ + foreach ($cart_select as $k => $v) { + $sell = Goods::where(['id' => $v['goods']])->value('sell'); + $cart_select[$k]['total'] = bcmul($v['cart_num'], $sell, 2); + $cart_select[$k]['price'] = $sell; + } + $order = [ + 'time' => time(), + 'number' => static::getNewOrderId('PF'), + 'total' => array_sum(array_column($cart_select, 'total')), + 'pay_type' => $params['pay_type'] ?? 0, + 'cart_id' => implode(',', $cartId) + ]; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; } - $order = [ - 'time' => time(), - 'number' => static::getNewOrderId('PF'), - 'total' => array_sum(array_column($cart_select, 'total')), - 'pay_type' => $params['pay_type']??0, - 'cart_id'=>implode(',',$cartId) - ]; return ['order' => $order, 'cart_list' => $cart_select]; } @@ -59,7 +64,7 @@ class OrderLogic extends BaseLogic $_order = $orderInfo['order']; $_order['deduction_price'] = 0; $_order['merchant'] = 0; - $_order['customer'] = request()->userId; + $_order['uid'] = request()->userId; $_order['money'] = 0; $_order['user'] = request()->userId; $_order['account'] = 0; @@ -73,6 +78,7 @@ class OrderLogic extends BaseLogic foreach ($goods_list as $k => $v) { $goods_list[$k]['pid'] = $order->id; $goods_list[$k]['merchant'] = 0; + $goods_list[$k]['uid'] = request()->userId; $goods_list[$k]['room'] = 0; $goods_list[$k]['discount'] = 0; $goods_list[$k]['warehouse'] = 0; @@ -88,30 +94,30 @@ class OrderLogic extends BaseLogic } } - /** + /** * @notes 获取购货订单购物车商品信息 * @param $params * @return array */ static public function cartIdByPurchaseOrderInfo($user, $params) { - if(!$user){ + if (!$user) { self::setError('没有用户信息,请先登录'); return false; } - $mer_id=$user['merchant']['mer_id']; - $where1=['paid'=>1]; - $cartId=Cashierclass::where('merchant',$mer_id)->whereDay('create_time')->where($where1)->column('cart_id'); - if(empty($cartId)){ + $mer_id = $user['merchant']['mer_id']; + $where1 = ['paid' => 1]; + $cartId = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('cart_id'); + if (empty($cartId)) { self::setError('没有购物车信息'); return false; } - $order_id=Cashierclass::where('merchant',$mer_id)->whereDay('create_time')->where($where1)->column('id'); - $cart_arr=[]; - foreach($cartId as $k=>$v){ - $arr=explode(',',$v); - foreach($arr as $kk=>$vv){ - $cart_arr[]=$vv; + $order_id = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('id'); + $cart_arr = []; + foreach ($cartId as $k => $v) { + $arr = explode(',', $v); + foreach ($arr as $kk => $vv) { + $cart_arr[] = $vv; } } $where = ['is_pay' => 1, 'is_fail' => 0]; @@ -130,9 +136,9 @@ class OrderLogic extends BaseLogic 'time' => time(), 'number' => static::getNewOrderId('CG'), 'total' => array_sum(array_column($cart_select, 'total')), - 'pay_type' => $params['pay_type']??0, - 'cart_id'=>implode(',',$cart_arr), - 'order_arr'=>implode(',',$order_id) + 'pay_type' => $params['pay_type'] ?? 0, + 'cart_id' => implode(',', $cart_arr), + 'order_arr' => implode(',', $order_id) ]; return ['order' => $order, 'cart_list' => $cart_select]; } @@ -143,18 +149,18 @@ class OrderLogic extends BaseLogic static public function createOpurchaseOrder($user = null, $params = []) { - if(!$user){ + if (!$user) { self::setError('没有用户信息,请先登录'); return false; } - $mer_id=$user['merchant']['mer_id']; - $merchant=Merchant::where('mer_id',$mer_id)->find(); + $mer_id = $user['merchant']['mer_id']; + $merchant = Merchant::where('mer_id', $mer_id)->find(); $orderInfo = self::cartIdByPurchaseOrderInfo($user, $params); - if(!$orderInfo){ + if (!$orderInfo) { return false; } $_order = $orderInfo['order']; - if($_order['total']<$merchant['mer_money']){ + if ($_order['total'] < $merchant['mer_money']) { self::setError('商户余额不足'); return false; } @@ -171,9 +177,9 @@ class OrderLogic extends BaseLogic $goods_list[$k]['nums'] = $v['cart_num']; } (new Opurchaseinfo())->saveAll($goods_list); - $merchant->mer_money=bcsub($merchant->mer_money,$_order['total'],2); - $order_arr=explode(',',$_order['order_arr']); - Cashierclass::where('id','in',$order_arr)->update(['is_opurchase'=>1]); + $merchant->mer_money = bcsub($merchant->mer_money, $_order['total'], 2); + $order_arr = explode(',', $_order['order_arr']); + Cashierclass::where('id', 'in', $order_arr)->update(['is_opurchase' => 1]); Db::commit(); return $order; } catch (\Exception $e) { diff --git a/app/api/logic/user/AddressLogic.php b/app/api/logic/user/AddressLogic.php new file mode 100644 index 0000000..c115d2c --- /dev/null +++ b/app/api/logic/user/AddressLogic.php @@ -0,0 +1,96 @@ + $params['uid'], + 'real_name' => $params['real_name'], + 'phone' => $params['phone'], + 'detail' => $params['detail'], + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑地址表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $data = [ + 'real_name' => $params['real_name'], + 'phone' => $params['phone'], + 'detail' => $params['detail'], + ]; + UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除地址表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function delete(array $params): bool + { + return UserAddress::destroy($params['address_id']); + } + + + /** + * @notes 获取购物车表详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public static function detail($params): array + { + return UserAddress::field('address_id,real_name,phone,detail')->findOrEmpty($params['address_id'])->toArray(); + } +} diff --git a/app/api/validate/UserAddressValidate.php b/app/api/validate/UserAddressValidate.php new file mode 100644 index 0000000..d67cd49 --- /dev/null +++ b/app/api/validate/UserAddressValidate.php @@ -0,0 +1,91 @@ + 'require', + 'phone' => 'require', + 'detail' => 'require', + 'address_id' => 'require', + + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + + 'real_name' => '收货人姓名', + 'phone' => '收货人电话', + 'detail' => '收货人详细地址', + 'address_id' => '地址id', + + ]; + + + /** + * @notes 添加场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneAdd() + { + return $this->only(['real_name','phone','detail']); + } + + + /** + * @notes 编辑场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneEdit() + { + return $this->only(['real_name','phone','detail','address_id']); + } + + + /** + * @notes 删除场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneDelete() + { + return $this->only(['address_id']); + } + + + /** + * @notes 详情场景 + * @return UserAddressValidate + * @author likeadmin + * @date 2024/04/28 17:28 + */ + public function sceneDetail() + { + return $this->only(['address_id']); + } + +} \ No newline at end of file diff --git a/app/api/validate/WechatLoginValidate.php b/app/api/validate/WechatLoginValidate.php new file mode 100644 index 0000000..323a5ed --- /dev/null +++ b/app/api/validate/WechatLoginValidate.php @@ -0,0 +1,96 @@ + 'require', + 'nickname' => 'require', + 'headimgurl' => 'require', + 'openid' => 'require', + 'access_token' => 'require', + 'terminal' => 'require', + 'avatar' => 'require', + ]; + + protected $message = [ + 'code.require' => 'code缺少', + 'nickname.require' => '昵称缺少', + 'headimgurl.require' => '头像缺少', + 'openid.require' => 'opendid缺少', + 'access_token.require' => 'access_token缺少', + 'terminal.require' => '终端参数缺少', + 'avatar.require' => '头像缺少', + ]; + + + /** + * @notes 公众号登录场景 + * @return WechatLoginValidate + * @author 段誉 + * @date 2022/9/16 10:57 + */ + public function sceneOa() + { + return $this->only(['code']); + } + + + /** + * @notes 小程序-授权登录场景 + * @return WechatLoginValidate + * @author 段誉 + * @date 2022/9/16 11:15 + */ + public function sceneMnpLogin() + { + return $this->only(['code']); + } + + + /** + * @notes + * @return WechatLoginValidate + * @author 段誉 + * @date 2022/9/16 11:15 + */ + public function sceneWechatAuth() + { + return $this->only(['code']); + } + + + /** + * @notes 更新用户信息场景 + * @return WechatLoginValidate + * @author 段誉 + * @date 2023/2/22 11:14 + */ + public function sceneUpdateUser() + { + return $this->only(['nickname', 'avatar']); + } + + +} \ No newline at end of file diff --git a/app/common/cache/UserTokenCache.php b/app/common/cache/UserTokenCache.php index 2e71cdd..970cbb8 100644 --- a/app/common/cache/UserTokenCache.php +++ b/app/common/cache/UserTokenCache.php @@ -16,6 +16,7 @@ namespace app\common\cache; use app\common\model\merchat\Merchant; +use app\common\model\supplier\Supplier; use app\common\model\user\User; use app\common\model\user\UserSession; use support\Cache; @@ -74,10 +75,12 @@ class UserTokenCache extends BaseCache $user = User::where('id', '=', $userSession->user_id) ->find(); $merchant=Merchant::where('uid',$userSession->user_id)->find(); + $supplier=Supplier::where('uid',$userSession->user_id)->find(); $userInfo = [ 'user_id' => $user->id, 'nickname' => $user->nickname, 'merchant' => $merchant, + 'supplier' => $supplier, 'token' => $token, 'sn' => $user->sn, 'mobile' => $user->mobile, diff --git a/app/common/logic/order/RetailOrderLogic.php b/app/common/logic/order/RetailOrderLogic.php index 5088337..cddb812 100644 --- a/app/common/logic/order/RetailOrderLogic.php +++ b/app/common/logic/order/RetailOrderLogic.php @@ -5,8 +5,10 @@ namespace app\common\logic\order; use app\common\enum\OrderEnum; use app\common\logic\BaseLogic; +use app\common\model\goods\Goods; use app\common\model\order\Cart; use app\common\model\order\FinancialRecord; +use app\common\model\retail\Cashierinfo; use app\common\model\user\User; use Exception; use support\Log; @@ -29,7 +31,7 @@ class RetailOrderLogic extends BaseLogic */ static public function payBalance(User $user, $order) { - if ($user['user_money'] < $order['actual']){ + if ($user['user_money'] < $order['actual']) { self::setError('余额不足,请更换支付方式'); return false; } @@ -42,7 +44,7 @@ class RetailOrderLogic extends BaseLogic 'financial_record_sn' => time(), 'order_id' => $order['id'], 'number_sn' => $order['number'], - 'user_id' => $order['customer'], + 'user_id' => $order['uid'], 'financial_type' => OrderEnum::USER_ORDER_PAY, 'financial_pm' => OrderEnum::EXPENDITURE, 'number' => $order['actual'], @@ -55,7 +57,7 @@ class RetailOrderLogic extends BaseLogic 'financial_record_sn' => time(), 'order_id' => $order['id'], 'number_sn' => $order['number'], - 'user_id' => $order['customer'], + 'user_id' => $order['uid'], 'financial_type' => OrderEnum::MERCHANT_ORDER_OBTAINS, 'financial_pm' => OrderEnum::INCOME, 'number' => $order['actual'], @@ -87,12 +89,12 @@ class RetailOrderLogic extends BaseLogic $order->money = $CallbackData['money']; $order->paid = 1; $order->save(); - if($order['cart_id']){ - if(!is_array($order['cart_id'])){ - $cart_arr=explode(',',$order['cart_id']); - Cart::whereIn('cart_id',$cart_arr)->update(['is_pay'=>1]); - }else{ - Cart::whereIn('cart_id',$order['cart_id'])->update(['is_pay'=>1]); + if ($order['cart_id']) { + if (!is_array($order['cart_id'])) { + $cart_arr = explode(',', $order['cart_id']); + Cart::whereIn('cart_id', $cart_arr)->update(['is_pay' => 1]); + } else { + Cart::whereIn('cart_id', $order['cart_id'])->update(['is_pay' => 1]); } } Log::info('支付成功'); @@ -102,10 +104,25 @@ class RetailOrderLogic extends BaseLogic } catch (\Exception $e) { // 回滚事务 Db::rollback(); - Log::error('支付失败'.$e->getMessage().'。like:'.$e->getLine()); - self::setError('支付失败'.$e->getMessage()); + Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); + self::setError('支付失败' . $e->getMessage()); return false; } + } + /** + * 获取用户常用购买记录 + */ + public static function frequentlyPurchase($params) + { + try { + $goods_id = Cashierinfo::where('uid', Request()->uid)->page($params['page'])->limit(50)->column('goods_id'); + $goods_arr = array_unique($goods_id); + $select = Goods::where('id', 'in', $goods_arr)->field('id,name,sell,imgs')->select(); + return $select; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } } } diff --git a/app/common/model/goods/Goods.php b/app/common/model/goods/Goods.php index aab29ae..1c00e10 100644 --- a/app/common/model/goods/Goods.php +++ b/app/common/model/goods/Goods.php @@ -48,7 +48,7 @@ class Goods extends BaseModel } public function unitName() { - return $this->hasOne(Unit::class,'id','unit')->bind(['unit_name'=>'name']); + return $this->hasOne(Unit::class,'id','unit')->bind(['unit_name'=>'name','is_bulk']); } public function warehouseName() { diff --git a/app/common/model/merchat/Merchant.php b/app/common/model/merchat/Merchant.php index c414bee..ac7cfb5 100644 --- a/app/common/model/merchat/Merchant.php +++ b/app/common/model/merchat/Merchant.php @@ -15,6 +15,7 @@ use think\model\concern\SoftDelete; class Merchant extends BaseModel { use SoftDelete; + protected $ok = 'mer_id'; protected $name = 'merchant'; protected $deleteTime = 'delete_time'; diff --git a/app/common/model/opurchase/OpurchaseGoodsOffer.php b/app/common/model/opurchase/OpurchaseGoodsOffer.php new file mode 100644 index 0000000..4b214c6 --- /dev/null +++ b/app/common/model/opurchase/OpurchaseGoodsOffer.php @@ -0,0 +1,22 @@ +upload($saveDir)) { throw new Exception($StorageDriver->getError()); } @@ -52,13 +52,12 @@ class UploadService $nameEnd = substr($fileInfo['name'], strlen($fileInfo['name'])-5, strlen($fileInfo['name'])); $fileInfo['name'] = $name . $nameEnd; } - // 4、写入数据库中 $file = File::create([ 'cid' => $cid, 'type' => FileEnum::IMAGE_TYPE, 'name' => $fileInfo['name'], - 'uri' => 'http://'.request()->host().$uriPath.'/' . str_replace("\\","/", $fileName), + 'uri' => $saveDir . '/' . str_replace("\\","/", $fileName), 'source' => $source, 'source_id' => $sourceId, 'create_time' => time(), diff --git a/app/common/service/storage/engine/Aliyun.php b/app/common/service/storage/engine/Aliyun.php index ad418b4..f7231fc 100755 --- a/app/common/service/storage/engine/Aliyun.php +++ b/app/common/service/storage/engine/Aliyun.php @@ -40,7 +40,7 @@ class Aliyun extends Server ); $ossClient->uploadFile( $this->config['bucket'], - $this->fileName, + $save_dir.'/'.$this->fileName, $this->getRealPath() ); } catch (OssException $e) {