From 5b0d7b0ca2af6a39220d2008bbf9ac2df7fed4ee Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 17 Jan 2024 16:22:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E9=93=BE=20-=20=E4=BE=9B=E5=BA=94=E5=95=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E3=80=81=E4=BE=9B=E5=BA=94=E5=95=86=E5=88=97=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E5=A4=8D=EF=BC=9A?= =?UTF-8?q?=E9=85=92=E9=81=93=E9=A6=86=E4=BD=BF=E7=94=A8=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=EF=BC=8C=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=85=91=E6=8D=A2=E7=94=A8=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E7=A7=AF=E5=88=86=EF=BC=8C=E5=AE=9E=E9=99=85=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BA=86=E6=93=8D=E4=BD=9C=E5=91=98=E7=9A=84=E7=A7=AF=E5=88=86?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D:=E8=AE=A2=E5=8D=95=E6=A0=B8=E9=94=80?= =?UTF-8?q?=E5=90=8E=E6=9C=AA=E6=88=90=E5=8A=9F=E8=A7=A3=E5=86=BB=E9=85=92?= =?UTF-8?q?=E5=8D=A1=E9=A2=9D=E5=BA=A6=20=E4=BF=AE=E5=A4=8D=EF=BC=9A?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81=E7=A0=81=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 7 +- .../admin/system/supplier/Supplier.php | 83 +++ app/controller/api/user/Exchange.php | 2 +- app/dao/BaseDao.php | 2 +- app/dao/supplier/SystemSupplierDao.php | 22 + app/event.php | 11 +- .../exchangeQuota/OrderVerifyEvent.php | 73 +++ .../supplier/SystemSupplierServices.php | 509 ++++++++++-------- route/admin/supplier.php | 43 ++ 9 files changed, 509 insertions(+), 243 deletions(-) create mode 100644 app/controller/admin/system/supplier/Supplier.php create mode 100644 app/listener/exchangeQuota/OrderVerifyEvent.php create mode 100644 route/admin/supplier.php diff --git a/app/common.php b/app/common.php index 621729a..0c64202 100644 --- a/app/common.php +++ b/app/common.php @@ -1056,11 +1056,10 @@ if (!function_exists('aj_captcha_check_two')) { * @param string $pointJson * @return bool */ - function aj_captcha_check_two(string $captchaType, string $captchaVerification,string $token) - { - // aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification); + function aj_captcha_check_two(string $captchaType, string $captchaVerification,string $token = ''){ + if($token) aj_get_serevice($captchaType)->verificationByEncryptCodeV2($captchaVerification,$token); + else aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification); - aj_get_serevice($captchaType)->verificationByEncryptCodeV2($captchaVerification,$token); return true; } } diff --git a/app/controller/admin/system/supplier/Supplier.php b/app/controller/admin/system/supplier/Supplier.php new file mode 100644 index 0000000..ec28293 --- /dev/null +++ b/app/controller/admin/system/supplier/Supplier.php @@ -0,0 +1,83 @@ +services = $services; + } + /** + * Common: 账号添加 + * Author: wu-hui + * Time: 2024/01/17 11:43 + * @return mixed + */ + public function accountCreate(){ + // 参数获取 + $data = $this->checkParam(); + // 添加账号 + $this->services->create((array)$data); + + return app('json')->success('添加成功'); + } + /** + * Common: 添加|编辑 账号参数获取 + * Author: wu-hui + * Time: 2024/01/17 10:56 + * @return array + */ + private function checkParam():array{ + // 接收表单参数 + $supplierId = (int)$this->request->param('supplier_id'); + $accountInfo = $this->request->params([ + 'supplier_name', + 'detailed_address', + 'name', + ['phone',''], + 'email', + 'sort', + 'is_show', + 'is_examine', + 'mark', + ]); + $accountPassword = $this->request->params([ + 'supplier_account', + 'supplier_password', + ]); + // 数据判断 + $nameIsHave = $this->services->isHave('supplier_name',$accountInfo['supplier_name'],$supplierId); + if($nameIsHave) throw new ValidateException('供应商名称已经存在,请勿重复添加!'); + if (!empty($accountInfo['phone']) && isPhone($accountInfo['phone'])) throw new ValidateException('请输入正确的手机号!'); + $accountIsHas = $this->services->accountIsHas($accountPassword['supplier_account'],$supplierId); + if($accountIsHas) throw new ValidateException('账号已存在,请勿重复添加!'); + + return compact('supplierId','accountInfo','accountPassword'); + } + /** + * Common: 获取列表 + * Author: wu-hui + * Time: 2024/01/17 14:29 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(){ + $search = $this->request->params(['supplier_name','name','phone','is_show']); + [$page, $limit] = $this->getPage(); + + $field = 'id,supplier_name,avatar,name,phone,is_show,add_time'; + $data = $this->services->supplierList($search, $page, $limit, $field); + + return app('json')->success($data); + } + + +} diff --git a/app/controller/api/user/Exchange.php b/app/controller/api/user/Exchange.php index c17f188..2fc52c2 100644 --- a/app/controller/api/user/Exchange.php +++ b/app/controller/api/user/Exchange.php @@ -32,7 +32,6 @@ class Exchange extends BaseController{ public function getUserHold(){ $params = $this->request->params(['consume_uid']); $uid = $this->request->uid(); - $user = $this->request->userInfo(); // 判断:是否存在指定消费者,不存在则使用当前登录用户 $uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid; // 获取额度 @@ -45,6 +44,7 @@ class Exchange extends BaseController{ ]) ->where('uid',$uid) ->findOrEmpty(); + $user = app()->make(UserRepository::class)->getSearch([])->where('uid',$uid)->findOrEmpty(); $info->available = (float)$info->available; $info->available_integral = (float)$user->exchange_integral; $info->diff_rate = 30;// 差价 应补金额,默认为30% diff --git a/app/dao/BaseDao.php b/app/dao/BaseDao.php index 7f6f078..a51b8e4 100644 --- a/app/dao/BaseDao.php +++ b/app/dao/BaseDao.php @@ -90,7 +90,7 @@ abstract class BaseDao * 获取模型 * @return BaseModel */ - protected function getModel() + public function getModel() { return app()->make($this->setModel()); } diff --git a/app/dao/supplier/SystemSupplierDao.php b/app/dao/supplier/SystemSupplierDao.php index 771603e..ab92b2e 100644 --- a/app/dao/supplier/SystemSupplierDao.php +++ b/app/dao/supplier/SystemSupplierDao.php @@ -50,4 +50,26 @@ class SystemSupplierDao extends BaseDao $query->order($order); })->field($field)->select()->toArray(); } + + // 公共搜索模型 + public function searchModel(array $search){ + $query = $this->getModel() + ->when(isset($search['supplier_name']) && $search['supplier_name'] !== '', function ($query) use ($search) { + $query->where('supplier_name','like', "%{$search['supplier_name']}%"); + }) + ->when(isset($search['name']) && $search['name'] !== '', function ($query) use ($search) { + $query->where('name','like', "%{$search['name']}%"); + }) + ->when(isset($search['phone']) && $search['phone'] !== '', function ($query) use ($search) { + $query->where('phone', $search['phone']); + }) + ->when(isset($search['is_show']) && $search['is_show'] !== '', function ($query) use ($search) { + $query->where('is_show', $search['is_show']); + }) + ->where('is_del',0); + + return $query; + } + + } diff --git a/app/event.php b/app/event.php index 2de66f4..e5e8b9a 100644 --- a/app/event.php +++ b/app/event.php @@ -55,17 +55,22 @@ return [ 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], // 订单支付成功事件触发 'order.paySuccess' => [ - // 赠送兑换额度 + // 赠送酒卡额度 'app\listener\exchangeQuota\OrderPaySuccessEvent' ], // 订单完成事件触发(进入待评价) 'order.take' => [ - // 兑换额度解冻 + // 酒卡额度解冻 'app\listener\exchangeQuota\OrderTakeEvent' ], + // 订单核销成功事件触发 + 'order.verify' => [ + // 酒卡额度解冻 + 'app\listener\exchangeQuota\OrderVerifyEvent' + ], // 订单退款事件 'refund.agree' => [ - // 兑换额度相关处理 + // 酒卡额度相关处理 'app\listener\exchangeQuota\OrderAgreeRefundEvent' ], ], diff --git a/app/listener/exchangeQuota/OrderVerifyEvent.php b/app/listener/exchangeQuota/OrderVerifyEvent.php new file mode 100644 index 0000000..d8e1515 --- /dev/null +++ b/app/listener/exchangeQuota/OrderVerifyEvent.php @@ -0,0 +1,73 @@ + $order->order_id,'uid' => $order->uid],1)); + // 判断:如果存在上级id 则使用上级id + $orderId = $order->main_id > 0 ? $order->main_id : $order->order_id; + # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 + $sum = (float)ExchangeQuotaRecord::where('order_id',$orderId) + ->where('change_type',1) + ->where('source',0) // 仅查询购买赠送 进行解冻 + ->sum('change_quantity'); + $refundSum = (float)ExchangeQuotaRecord::where('order_id',$orderId) + ->where('change_type',0) + ->where('source',1) // 仅查询订单退款 减少内容 + ->sum('change_quantity'); + // 剩余数量 解冻 + $surplusQuota = (float)sprintf("%.2f",$sum - $refundSum); + if($surplusQuota > 0){ + // 核销订单 会进行拆分操作 需要获取当前订单占总订单数量的比例 + $totalNum = (int)$this->getRate($orderId); + $currentTotalNum = (int)$order->total_num; + $rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100); + $surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100); + // 解冻操作 + $hold = ExchangeQuota::where('uid',$order->uid)->findOrEmpty(); + $freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota); + $hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota; + $hold->save(); + } + }catch(\Exception $e){ + Log::info('订单核销 - 酒卡额度相关处理 - 错误: '.$e->getMessage()); + } + } + /** + * Common: 获取订单总数量 + * Author: wu-hui + * Time: 2024/01/17 16:03 + * @param $orderId + * @return mixed + */ + public function getRate($orderId){ + return app()->make(StoreOrderRepository::class) + ->getSearch([]) + ->where(function($query) use ($orderId){ + $query->where('order_id',$orderId)->whereOr('main_id',$orderId); + })->sum('total_num'); + } + + + + + + + + + + +} \ No newline at end of file diff --git a/app/services/supplier/SystemSupplierServices.php b/app/services/supplier/SystemSupplierServices.php index 5232111..2dc830b 100644 --- a/app/services/supplier/SystemSupplierServices.php +++ b/app/services/supplier/SystemSupplierServices.php @@ -27,298 +27,339 @@ use think\exception\ValidateException; * @package app\services\supplier * @mixin SystemSupplierDao */ -class SystemSupplierServices extends BaseServices -{ - - protected $adminDao = null; - +class SystemSupplierServices extends BaseServices{ + protected $adminDao = NULL; /** * 构造方法 * SystemSupplierServices constructor. * @param SystemSupplierDao $dao - * @param SystemAdminDao $adminDao + * @param SystemAdminDao $adminDao */ - public function __construct(SystemSupplierDao $dao, SystemAdminDao $adminDao) - { - $this->dao = $dao; + public function __construct(SystemSupplierDao $dao,SystemAdminDao $adminDao){ + $this->dao = $dao; $this->adminDao = $adminDao; } - /** * 获取供应商 * @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\DataNotFoundException */ - public function getSupplierInfo(int $id, string $field = '*', array $with = []) - { - $info = $this->dao->getOne(['id' => $id, 'is_del' => 0], $field, $with); - if (!$info) { + public function getSupplierInfo(int $id,string $field = '*',array $with = []){ + $info = $this->dao->getOne(['id' => $id,'is_del' => 0],$field,$with); + if(!$info){ throw new ValidateException('供应商不存在'); } return $info; } - - /** - * 供应商列表 - * @param array $where - * @param array $field - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function getSupplierList(array $where, array $field = ['*']) - { - [$page, $limit] = $this->getPageValue(); - $list = $this->dao->getSupplierList($where, $field, $page, $limit); - if ($list) { - $prefix = config('admin.supplier_prefix'); - foreach ($list as &$item) { - if (isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']); - $item['prefix'] = $prefix; - } - } + /** + * 供应商列表 + * @param array $where + * @param array $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getSupplierList(array $where,array $field = ['*']){ + [$page,$limit] = $this->getPageValue(); + $list = $this->dao->getSupplierList($where,$field,$page,$limit); + if($list){ + $prefix = config('admin.supplier_prefix'); + foreach($list as &$item){ + if(isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s',$item['add_time']); + $item['prefix'] = $prefix; + } + } $count = $this->dao->count($where); - return compact('list', 'count'); + return compact('list','count'); } - - /** - * 保存供应商 - * @param array $data - * @return mixed - */ - public function create(array $data) - { - if ($this->adminDao->count(['account' => $data['account'], 'admin_type' => 4, 'is_del' => 0])) { - throw new AdminException('管理员账号已存在'); - } - return $this->transaction(function () use ($data) { - $adminData = [ - 'pwd' => $this->passwordHash($data['pwd']), - 'admin_type' => 4, - 'account' => $data['account'], - 'roles' => '', - 'real_name' => $data['name'], - 'phone' => $data['phone'], - 'add_time' => time(), - 'level' => 0 - ]; - unset($data['pwd'], $data['conf_pwd'], $data['account']); - - // 创建管理员 - $res = $this->adminDao->save($adminData); - if (!$res) throw new AdminException('管理员添加失败'); - $data['admin_id'] = (int)$res->id; - $data['add_time'] = time(); - - // 创建供应商 - $relation_id = $this->dao->save($data)->id; - if (!$relation_id) throw new AdminException('供应商添加失败'); - - $this->adminDao->update($res->id, ['relation_id' => $relation_id]); - return $relation_id; - }); - } - /** * 修改管理员 * @param array $data * @return mixed */ - public function save(int $id, array $data) - { - if (!$supplierInfo = $this->dao->get($id)) { - throw new AdminException('供应商不存在,无法修改'); - } - if ($supplierInfo->is_del) { - throw new AdminException('供应商已经删除'); - } - if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) { - throw new AdminException('管理员不存在,无法修改'); - } - if ($adminInfo->is_del) { - throw new AdminException('管理员已经删除'); - } - //修改账号 - if (isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'], $supplierInfo['admin_id'], 4)) { - throw new AdminException('管理员账号已存在'); - } - return $this->transaction(function () use ($id, $data, $adminInfo, $supplierInfo) { + public function save(int $id,array $data){ + if(!$supplierInfo = $this->dao->get($id)){ + throw new AdminException('供应商不存在,无法修改'); + } + if($supplierInfo->is_del){ + throw new AdminException('供应商已经删除'); + } + if(!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])){ + throw new AdminException('管理员不存在,无法修改'); + } + if($adminInfo->is_del){ + throw new AdminException('管理员已经删除'); + } + //修改账号 + if(isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'],$supplierInfo['admin_id'],4)){ + throw new AdminException('管理员账号已存在'); + } + return $this->transaction(function() use ($id,$data,$adminInfo,$supplierInfo){ - $adminData = [ - 'pwd' => $this->passwordHash($data['pwd']), - 'real_name' => $data['name'] ?? $adminInfo->real_name, - 'phone' => $data['phone'] ?? $adminInfo->phone, - 'account' => $data['account'] ?? $adminInfo->account - ]; + $adminData = [ + 'pwd' => $this->passwordHash($data['pwd']), + 'real_name' => $data['name'] ?? $adminInfo->real_name, + 'phone' => $data['phone'] ?? $adminInfo->phone, + 'account' => $data['account'] ?? $adminInfo->account + ]; // 修改管理员 - $res = $this->adminDao->update($adminInfo['id'], $adminData); - if (!$res) throw new AdminException('管理员修改失败'); - - // 修改供应商 - unset($data['pwd'], $data['conf_pwd'], $data['account']); - $this->dao->update($id, $data); + $res = $this->adminDao->update($adminInfo['id'],$adminData); + if(!$res) throw new AdminException('管理员修改失败'); + // 修改供应商 + unset($data['pwd'],$data['conf_pwd'],$data['account']); + $this->dao->update($id,$data); $res1 = $supplierInfo->save(); - if (!$res1) throw new AdminException('供应商修改失败'); - return true; + if(!$res1) throw new AdminException('供应商修改失败'); + return TRUE; }); } - - /** - * @param int $id - * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function delete(int $id) - { - if (!$supplierInfo = $this->dao->get($id)) { - throw new AdminException('供应商不存在,无法修改'); - } - if ($supplierInfo->is_del) { - throw new AdminException('供应商已经删除'); - } - if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) { - throw new AdminException('管理员不存在,无法删除'); - } - if ($adminInfo->is_del) { - throw new AdminException('管理员已经删除'); - } - /** @var StoreOrderServices $storeOrderServices */ - $storeOrderServices = app()->make(StoreOrderServices::class); - $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 0]); - if (!$orderCount) { - $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 1]); - if (!$orderCount) { - $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 5]); - } - } - if ($orderCount) { - return $this->fail('删除失败,该供应商还有待处理订单'); - } - return $this->transaction(function () use ($id, $supplierInfo, $adminInfo) { + /** + * @param int $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function delete(int $id){ + if(!$supplierInfo = $this->dao->get($id)){ + throw new AdminException('供应商不存在,无法修改'); + } + if($supplierInfo->is_del){ + throw new AdminException('供应商已经删除'); + } + if(!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])){ + throw new AdminException('管理员不存在,无法删除'); + } + if($adminInfo->is_del){ + throw new AdminException('管理员已经删除'); + } + /** @var StoreOrderServices $storeOrderServices */ + $storeOrderServices = app()->make(StoreOrderServices::class); + $orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 0]); + if(!$orderCount){ + $orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 1]); + if(!$orderCount){ + $orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 5]); + } + } + if($orderCount){ + return $this->fail('删除失败,该供应商还有待处理订单'); + } + return $this->transaction(function() use ($id,$supplierInfo,$adminInfo){ $adminInfo->status = 0; $adminInfo->is_del = 1; // 修改管理员 $res = $adminInfo->save(); - if (!$res) throw new AdminException('管理员删除失败'); - + if(!$res) throw new AdminException('管理员删除失败'); $supplierInfo->is_show = 0; - $supplierInfo->is_del = 1; + $supplierInfo->is_del = 1; // 修改供应商 $res1 = $supplierInfo->save(); - if (!$res1) throw new AdminException('供应商删除失败'); - - /** @var StoreBranchProductServices $storeBranchProducesServices */ - $storeBranchProducesServices = app()->make(StoreBranchProductServices::class); - //删除供应商商品 - $storeBranchProducesServices->deleteProducts([], 2, $id); - /** @var SystemAttachmentServices $attach */ - $attach = app()->make(SystemAttachmentServices::class); - //删除附件 - $attach->delAttachment([], 4, $id); - return true; + if(!$res1) throw new AdminException('供应商删除失败'); + /** @var StoreBranchProductServices $storeBranchProducesServices */ + $storeBranchProducesServices = app()->make(StoreBranchProductServices::class); + //删除供应商商品 + $storeBranchProducesServices->deleteProducts([],2,$id); + /** @var SystemAttachmentServices $attach */ + $attach = app()->make(SystemAttachmentServices::class); + //删除附件 + $attach->delAttachment([],4,$id); + return TRUE; }); } - - /** * 平台供应商运营统计 - * @param int $supplierId + * @param int $supplierId * @param array $time * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function supplierChart(int $supplierId, array $time) - { - $list = $this->dao->getSupplierList(['is_del' => 0, 'is_show' => 1], ['id', 'supplier_name']); + public function supplierChart(int $supplierId,array $time){ + $list = $this->dao->getSupplierList(['is_del' => 0,'is_show' => 1],['id','supplier_name']); /** @var StoreOrderServices $orderServices */ $orderServices = app()->make(StoreOrderServices::class); /** @var StoreOrderRefundServices $orderRefundServices */ $orderRefundServices = app()->make(StoreOrderRefundServices::class); - $where = ['time' => $time]; - - $order_where = ['paid' => 1, 'pid' => 0, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3]]; + $where = ['time' => $time]; + $order_where = ['paid' => 1,'pid' => 0,'is_del' => 0,'is_system_del' => 0,'refund_status' => [0,3]]; $refund_where = ['refund_type' => 6]; - foreach ($list as &$item) { - $supplier_where = ['supplier_id' => $item['id']]; - $item['order_price'] = $orderServices->sum($where + $supplier_where + $order_where, 'pay_price', true); - $item['order_count'] = $orderServices->count($where + $supplier_where + $order_where); - $item['refund_order_price'] = $orderRefundServices->sum($where + $supplier_where + $refund_where, 'refunded_price', true); + foreach($list as &$item){ + $supplier_where = ['supplier_id' => $item['id']]; + $item['order_price'] = $orderServices->sum($where + $supplier_where + $order_where,'pay_price',TRUE); + $item['order_count'] = $orderServices->count($where + $supplier_where + $order_where); + $item['refund_order_price'] = $orderRefundServices->sum($where + $supplier_where + $refund_where,'refunded_price',TRUE); $item['refund_order_count'] = $orderRefundServices->count($where + $supplier_where + $refund_where); } return $list; } + /** + * 供应商选择列表 + * @param array $where + * @param array $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getSupplierSearch(array $where,array $field = ['*']){ + return $this->dao->getSupplierList($where,$field,0,0); + } + /** + * 供应商入住审核通过创建数据 + * @param int $applyId + * @param array $info + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function verifyAgreeCreate(int $applyId,array $info = []){ + if(!$applyId){ + throw new ValidateException('缺少申请ID'); + } + /** @var SystemUserApplyServices $applyServices */ + $applyServices = app()->make(SystemUserApplyServices::class); + if(!$info){ + $info = $applyServices->get($applyId); + if(!$info){ + throw new ValidateException('申请数据不存在'); + } + $info = $info->toArray(); + } + $data = [ + 'supplier_name' => $info['system_name'], + 'account' => $this->getAccount($info['phone']), + 'phone' => $info['phone'], + 'name' => $info['name'], + 'pwd' => substr($info['phone'],-6) + ]; - /** - * 供应商选择列表 - * @param array $where - * @param array $field - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function getSupplierSearch(array $where, array $field = ['*']) - { - return $this->dao->getSupplierList($where, $field, 0, 0); + // todo 版本迭代 当前功能暂不可用 + throw new ValidateException('开发中...'); + // $supplier_id = $this->create($data); + // return $this->dao->get($supplier_id)->toArray(); + } + /** + * 获取同意申请 创建账号 + * @param string $phone + * @return string + */ + public function getAccount(string $phone){ + $account = ''; + if($phone){ + //当前手机号当作账号是否存在 + $adminDCount = $this->adminDao->count(['account' => $phone,'admin_type' => 4,'is_del' => 0]); + $account = $phone; + if($adminDCount){ + $account = $account.'_'.$adminDCount; + } + } + return $account; + } + + + + ////////////////////////////////////////////////////////////////////////////////// + + /** + * Common: 添加供应商 + * Author: wu-hui + * Time: 2024/01/17 11:43 + * @param array $data + * @return mixed + */ + public function create(array $data){ + return $this->transaction(function() use ($data){ + // 添加供应商信息 + $relation_id = $this->dao->save($data['accountInfo'])->id; + if(!$relation_id) throw new AdminException('供应商添加失败'); + // 添加账号信息 + $accountPassword = $data['accountPassword']; + $adminId = (int)$this->adminDao->getModel()->insertGetId([ + 'pwd' => $this->passwordHash($accountPassword['supplier_password']), + 'admin_type' => 4, + 'account' => $accountPassword['supplier_account'], + 'roles' => 1, + 'real_name' => $data['accountInfo']['supplier_name'], + 'phone' => $data['accountInfo']['phone'], + 'level' => 0, + 'relation_id' => $relation_id + ]); + if($adminId <= 0) throw new AdminException('管理员添加失败'); + // 修改超级管理员关联 + $this->dao->update($relation_id,['admin_id' => (int)$adminId]); + + return $relation_id; + }); + } + /** + * Common: 某个数据是否已经存在 + * Author: wu-hui + * Time: 2024/01/17 10:28 + * @param $field + * @param $fieldValue + * @param int $supplierId + * @return bool + */ + public function isHave($field,$fieldValue,int $supplierId = 0):bool{ + $count = $this->dao->getModel() + ->where($field,$fieldValue) + ->when($supplierId > 0,function($query) use ($supplierId){ + $query->where('id','<>',$supplierId); + }) + ->count(); + return $count > 0; + } + /** + * Common: 账号是否存在 + * Author: wu-hui + * Time: 2024/01/17 10:53 + * @param $account + * @param int $supplierId + * @return bool + */ + public function accountIsHas($account,int $supplierId = 0):bool{ + $count = $this->adminDao->getModel() + ->where('account',$account) + ->where('admin_type',4) + ->where('is_del',0) + ->when($supplierId > 0,function($query) use ($supplierId){ + $query->where('relation_id','<>',$supplierId); + }) + ->count(); + return $count > 0; + } + + + /** + * Common: 获取列表 + * Author: wu-hui + * Time: 2024/01/17 14:28 + * @param $search + * @param $page + * @param $limit + * @param string $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function supplierList($search, $page, $limit, $field = '*'){ + $query = $this->dao->searchModel($search); + $list = $query + ->field($field) + ->order('add_time desc,id desc') + ->page($page, $limit) + ->select(); + $count = $query->count(); + + return compact('count', 'list'); } - /** - * 供应商入住审核通过创建数据 - * @param int $applyId - * @param array $info - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function verifyAgreeCreate(int $applyId, array $info = []) - { - if (!$applyId) { - throw new ValidateException('缺少申请ID'); - } - /** @var SystemUserApplyServices $applyServices */ - $applyServices = app()->make(SystemUserApplyServices::class); - if (!$info) { - $info = $applyServices->get($applyId); - if (!$info) { - throw new ValidateException('申请数据不存在'); - } - $info = $info->toArray(); - } - $data = [ - 'supplier_name' => $info['system_name'], - 'account' => $this->getAccount($info['phone']), - 'phone' => $info['phone'], - 'name' => $info['name'], - 'pwd' => substr($info['phone'], -6) - ]; - $supplier_id = $this->create($data); - return $this->dao->get($supplier_id)->toArray(); - } - /** - * 获取同意申请 创建账号 - * @param string $phone - * @return string - */ - public function getAccount(string $phone) - { - $account = ''; - if ($phone) { - //当前手机号当作账号是否存在 - $adminDCount = $this->adminDao->count(['account' => $phone, 'admin_type' => 4, 'is_del' => 0]); - $account = $phone; - if ($adminDCount) { - $account = $account . '_' . $adminDCount; - } - } - return $account; - } } diff --git a/route/admin/supplier.php b/route/admin/supplier.php new file mode 100644 index 0000000..4660059 --- /dev/null +++ b/route/admin/supplier.php @@ -0,0 +1,43 @@ +name('systemSupplierAccountCreate')->option([ + '_alias' => '账号添加', + ]); + + + + // 供应商信息 + Route::get('list', '/getList')->name('systemSupplierList')->option([ + '_alias' => '供应商列表', + ]); + + + + + + }) + ->prefix('admin.system.supplier.Supplier') + ->option([ + '_path' => '/supplier/supplier', + '_auth' => true, + ]); + + + + + + +}) + ->middleware(AllowOriginMiddleware::class) + ->middleware(AdminTokenMiddleware::class, true) + ->middleware(AdminAuthMiddleware::class) + ->middleware(LogMiddleware::class);