From d7e3e8e8f8f8c086c3e4e622433cd08f9d24dbba Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 27 May 2024 14:03:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=95=86=E6=88=B7=E5=A2=9E=E5=8A=A0=E8=A1=A5=E8=B4=A7=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/MerchantQuotaRecordDao.php | 41 ++++++++ .../system/merchant/MerchantQuotaRecord.php | 26 +++++ .../MerchantQuotaRecordRepository.php | 94 +++++++++++++++++++ .../system/merchant/MerchantRepository.php | 3 +- .../admin/system/merchant/Merchant.php | 35 +++++++ route/admin/merchant.php | 9 +- 6 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 app/common/dao/system/merchant/MerchantQuotaRecordDao.php create mode 100644 app/common/model/system/merchant/MerchantQuotaRecord.php create mode 100644 app/common/repositories/system/merchant/MerchantQuotaRecordRepository.php diff --git a/app/common/dao/system/merchant/MerchantQuotaRecordDao.php b/app/common/dao/system/merchant/MerchantQuotaRecordDao.php new file mode 100644 index 0000000..0b5e371 --- /dev/null +++ b/app/common/dao/system/merchant/MerchantQuotaRecordDao.php @@ -0,0 +1,41 @@ +when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ + $query->where('id',(int)$params['id']); + }) + ->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){ + $query->where('mer_id',(int)$params['mer_id']); + }) + ->with([ + 'merchant' => function($query){ + $query->field('mer_id,mer_name,mer_avatar'); + }, + ]) + ->order('create_time DESC,id DESC'); + } + + + + + + + +} diff --git a/app/common/model/system/merchant/MerchantQuotaRecord.php b/app/common/model/system/merchant/MerchantQuotaRecord.php new file mode 100644 index 0000000..2545fde --- /dev/null +++ b/app/common/model/system/merchant/MerchantQuotaRecord.php @@ -0,0 +1,26 @@ +hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + + + + + +} diff --git a/app/common/repositories/system/merchant/MerchantQuotaRecordRepository.php b/app/common/repositories/system/merchant/MerchantQuotaRecordRepository.php new file mode 100644 index 0000000..0fb0d18 --- /dev/null +++ b/app/common/repositories/system/merchant/MerchantQuotaRecordRepository.php @@ -0,0 +1,94 @@ +dao = $dao; + } + /** + * Common: 补货额度变更明细列表 + * Author: wu-hui + * Time: 2024/05/27 13:52 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $params,int $page,int $limit){ + $query = $this->dao->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list'); + } + /** + * Common: 商户补货额度变更 并且添加变更记录 + * Author: wu-hui + * Time: 2024/05/27 11:51 + * @param $params + * @return array|\think\Model + */ + public function changeQuota($params){ + $quantity = abs($params['change_quantity'] ?? 0); + $merId = $params['mer_id'] ?? 0; + // 是否允许生成兑换码 + if(!in_array((int)$params['change_type'],[0, 1])) throw new ValidateException('非法请求,变更类型不明确!'); + if($quantity <= 0) throw new ValidateException('变更数量必须大于0!'); + if($merId <= 0) throw new ValidateException('非法请求,商户不明确!'); + // 处理 + Db::startTrans(); + try{ + // 获取商户信息 + $merInfo = app()->make(MerchantRepository::class)->getSearch(['mer_id'=>$merId])->field('quota_total,quota_used,quota_surplus')->findOrEmpty(); + $changeFront = $merInfo->quota_surplus ?? 0;// 变更前数量 + // 根据操作类型进行处理 变更类型:0=减少,1=增加 + if((int)$params['change_type'] == 1){ + // 增加 + $changeAfter = sprintf("%.2f", $changeFront + $quantity); + $merInfo->quota_total += $quantity; + $merInfo->quota_surplus += $quantity; + }else{ + // 减少 + $changeAfter = sprintf("%.2f", $changeFront - $quantity); + $merInfo->quota_surplus -= $quantity; + if($merInfo->quota_surplus < 0) throw new ValidateException('操作失败,剩余额度不足!'); + } + $merInfo->save(); + // 记录 + $record = [ + 'mer_id' => $merId, + 'change_type' => (int)$params['change_type'], + 'change_front' => $changeFront, + 'change_quantity' => $quantity, + 'change_after' => $changeAfter, + ]; + $this->dao->create($record); + + Db::commit(); + + return $merInfo; + }catch(\Exception $e){ + Db::rollback(); + throw new ValidateException($e->getMessage()); + } + } + + + + + + + + + +} diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 2bed838..33357cc 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -101,7 +101,8 @@ class MerchantRepository extends BaseRepository $query->field('uid,nickname,avatar'); }, ]) - ->field('resource_shareholders_uid,merchant_type,sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time,agent_id,shop_mer_id,brand_id')->select(); + ->field('quota_total,quota_used,quota_surplus,resource_shareholders_uid,merchant_type,sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time,agent_id,shop_mer_id,brand_id') + ->select(); return compact('count', 'list'); } diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index 2d0b198..5af2e55 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -8,6 +8,7 @@ namespace app\controller\admin\system\merchant; use app\common\repositories\store\product\ProductCopyRepository; use app\common\repositories\store\service\StoreServiceRepository; +use app\common\repositories\system\merchant\MerchantQuotaRecordRepository; use app\common\repositories\system\merchant\MerchantTypeRepository; use app\common\repositories\user\UserBillRepository; use crmeb\basic\BaseController; @@ -375,4 +376,38 @@ class Merchant extends BaseController $data = $this->repository->adminDetail($id); return app('json')->success($data); } + + /** + * Common: 补货额度 - 变更 + * Author: wu-hui + * Time: 2024/05/27 11:51 + * @return mixed + */ + public function quotaChange(){ + $params = $this->request->params([ + 'change_type', + ['change_quantity', 0], + ['mer_id', 0] + ]); + app()->make(MerchantQuotaRecordRepository::class)->changeQuota($params); + + return app('json')->success('变更成功'); + } + /** + * Common: 补货额度 - 变更记录明细 + * Author: wu-hui + * Time: 2024/05/27 13:53 + * @return mixed + */ + public function quotaChangeRecord(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params([ + ['mer_id', 0] + ]); + $result = app()->make(MerchantQuotaRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($result); + } + + } diff --git a/route/admin/merchant.php b/route/admin/merchant.php index d883261..5a9817f 100644 --- a/route/admin/merchant.php +++ b/route/admin/merchant.php @@ -105,7 +105,7 @@ Route::group(function () { Route::group('system/merchant', function () { Route::get('create/form', '.Merchant/createForm')->name('systemMerchantCreateForm')->option([ '_alias' => '商户列表', - ]); + ]); Route::get('count', '.Merchant/count')->name('systemMerchantCount')->option([ '_alias' => '商户列表统计', ]); @@ -159,6 +159,13 @@ Route::group(function () { Route::get('detail/:id', '.Merchant/detail')->name('systemMerchantDetail')->option([ '_alias' => '详情', ]); + // 补货额度 + Route::post('quota/change', '.Merchant/quotaChange')->name('systemMerchantQuotaChange'); + Route::post('quota/change_record', '.Merchant/quotaChangeRecord')->name('systemMerchantQuotaChange'); + + + + })->prefix('admin.system.merchant')->option([ '_path' => '/merchant/list', '_auth' => true,