From 45468a70a18c95a9ad3d4770dcb58dd01e97d85b Mon Sep 17 00:00:00 2001 From: liuxiaoquan Date: Mon, 13 Mar 2023 11:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E5=85=A5=E9=A9=BB=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/merchant/MerchantIntention.php | 28 +++- .../system/merchant/intention/lst.html | 47 +++++-- .../system/merchant/intention/status.html | 66 +++++++++ .../system/merchant/MerchantIntention.php | 132 +++++++++++++++++- 4 files changed, 256 insertions(+), 17 deletions(-) create mode 100644 app/admin/view/merchant/system/merchant/intention/status.html diff --git a/app/admin/controller/merchant/system/merchant/MerchantIntention.php b/app/admin/controller/merchant/system/merchant/MerchantIntention.php index 66f14dd..282cf95 100644 --- a/app/admin/controller/merchant/system/merchant/MerchantIntention.php +++ b/app/admin/controller/merchant/system/merchant/MerchantIntention.php @@ -29,6 +29,7 @@ class MerchantIntention extends BaseController $this->intention = $intention; $this->path = [ 'index' => 'merchant/system/merchant/intention/lst', + 'status' => 'merchant/system/merchant/intention/status', 'mark' => 'merchant/system/merchant/intention/mark', 'read' => 'merchant/system/merchant/intention/read', 'add' => 'merchant/system/merchant/intention/add' @@ -69,9 +70,34 @@ class MerchantIntention extends BaseController return to_assign(0, '', $data); } + /** + * 审核表单 + */ public function StatusForm() { - return View($this->path['index']); + $id = get_params('id'); + if (!$this->intention->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) + return to_assign(1,'数据不存在'); + + return View($this->path['status'], ['id'=>$id]); + } + + /** + * 审核 + */ + public function SwitchStatus() + { + $params = get_params(['status','fail_msg','create_mer','id']); + $id = $params['id']; + + //创建 + if (!$this->intention->GetWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) + return to_assign(1,'数据不存在'); + + $params['status'] = $params['status'] == 1 ? 1 : 2; + $this->intention->updateStatus($id, $params); + + return to_assign(0,'修改成功'); } public function MarkForm() diff --git a/app/admin/view/merchant/system/merchant/intention/lst.html b/app/admin/view/merchant/system/merchant/intention/lst.html index 8389bb8..99b24ba 100644 --- a/app/admin/view/merchant/system/merchant/intention/lst.html +++ b/app/admin/view/merchant/system/merchant/intention/lst.html @@ -17,15 +17,15 @@
-
- - - - - - - - +
+ + + + + + + +
@@ -52,8 +52,8 @@
-
- +
+ @@ -67,10 +67,10 @@
- {volist name="category" key="k" id="vo"} - + {/volist}
@@ -88,10 +88,10 @@
- {volist name="type" key="k" id="vo"} - + {/volist}
@@ -124,6 +124,7 @@ +{/block} + \ No newline at end of file diff --git a/app/common/model/merchant/system/merchant/MerchantIntention.php b/app/common/model/merchant/system/merchant/MerchantIntention.php index aaba01c..febcf25 100644 --- a/app/common/model/merchant/system/merchant/MerchantIntention.php +++ b/app/common/model/merchant/system/merchant/MerchantIntention.php @@ -12,6 +12,7 @@ namespace app\common\model\merchant\system\merchant; use app\common\model\merchant\system\merchant\MerchantCategory; use think\Model; +use think\exception\ValidateException; /** * @mixin \think\Model @@ -102,10 +103,139 @@ class MerchantIntention extends Model $this->getModel()::getDB()->where($this->getPk(), $id)->update(['status' => $data['status'], 'mark' => $data['mark']]); } + /** + * 数据是否存在 + */ public function GetWhereCount($mer_intention_id) { - $count = self::where(['mer_intention_id' => $mer_intention_id, 'is_del' => 0])->fetchSql()->count(); + echo $count = self::where(['mer_intention_id' => $mer_intention_id, 'is_del' => 0])->count(); return $count; } + + /** + * 审核 + * TODO: 未完全 + */ + public function updateStatus($id, $data) + { + $create = $data['create_mer'] == 1; + unset($data['create_mer']); + $intention = $this->search(['mer_intention_id' => $id])->find(); + $smsData = []; + if (!$intention) + throw new ValidateException('信息不存在'); + if ($intention->status) + throw new ValidateException('状态有误,修改失败'); + + //TODO: 此处需开发为可配置字段 + $config = ['broadcast_room_type'=>0, 'broadcast_goods_type'=>0]; + + $margin = app()->make(MerchantTypeRepository::class)->get($intention['mer_type_id']); + $data['is_margin'] = $margin['is_margin'] ?? -1; + $data['margin'] = $margin['margin'] ?? 0; + $merData = []; + if ($create) { + $password = substr($intention['phone'], -6); + $merData = [ + 'mer_name' => $intention['mer_name'], + 'mer_phone' => $intention['phone'], + 'mer_account' => $intention['phone'], + 'category_id' => $intention['merchant_category_id'], + 'type_id' => $intention['mer_type_id'], + 'real_name' => $intention['name'], + 'status' => 1, + 'is_audit' => 1, + // 'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1, + // 'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1, + 'is_bro_room' => empty($config['broadcast_room_type']) ? 0 : 1, + 'is_bro_goods' => !empty($config['broadcast_goods_type']) ? 0 : 1, + 'mer_password' => $password, + 'is_margin' => $margin['is_margin'] ?? -1, + 'margin' => $margin['margin'] ?? 0, + 'area_id' => $intention['area_id'] ?? 0, + 'geo_street' => $intention['street_id'] ?? 0, + 'village_id' => $intention['village_id'] ?? 0, + 'is_nmsc' => $intention['is_nmsc'] ?? 0, + ]; + if ($data['status'] == 1) { + $data['fail_msg'] = ''; + $smsData = [ + 'date' => date('m月d日', strtotime($intention->create_time)), + 'mer' => $intention['mer_name'], + 'phone' => $intention['phone'], + 'pwd' => $password ?? '', + // 'site_name' => systemConfig('site_name'), + ]; + } + } + if ($data['status'] == 2) { + $smsData = [ + 'phone' => $intention['phone'], + 'date' => date('m月d日', strtotime($intention->create_time)), + 'mer' => $intention['mer_name'], + // 'site' => systemConfig('site_name'), + ]; + } + + self::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) { + if ($data['status'] == 1) { + if ($create) { + $merchant = self::createMerchant($merData); + $data['mer_id'] = $merchant->mer_id; + // 暂不开通通知 + // Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]); + } + } else { + // Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]); + } + $intention->save($data); + }); + } + + + + /** + * @param array $data + * @author xaboy + * @day 2020-04-17 + */ + protected function createMerchant(array $data) + { + if ($this->fieldExists('mer_name', $data['mer_name'])) + throw new ValidateException('商户名已存在'); + if ($data['mer_phone'] && isPhone($data['mer_phone'])) + throw new ValidateException('请输入正确的手机号'); + $merchantCategoryRepository = app()->make(MerchantCategoryRepository::class); + $adminRepository = app()->make(MerchantAdminRepository::class); + + if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) + throw new ValidateException('商户分类不存在'); + if ($adminRepository->fieldExists('account', $data['mer_account'])) + throw new ValidateException('账号已存在'); + + /** @var MerchantAdminRepository $make */ + $make = app()->make(MerchantAdminRepository::class); + + $margin = app()->make(MerchantTypeRepository::class)->get($data['type_id']); + $data['is_margin'] = $margin['is_margin'] ?? -1; + $data['margin'] = $margin['margin'] ?? 0; + + return Db::transaction(function () use ($data, $make) { + $account = $data['mer_account']; + $password = $data['mer_password']; + unset($data['mer_account'], $data['mer_password']); + + $merchant = $this->dao->create($data); + $make->createMerchantAccount($merchant, $account, $password); + $address_id = Db::name('merchant_address')->insertGetId(['mer_id'=>$merchant->mer_id,'street_id'=>$data['geo_street']]); + if($data['area_id'] && $data['village_id']){ + Db::name('merchant_address')->where('id',$address_id)->update(['area_id'=>$data['area_id'],'village_id'=>$data['village_id']]); + } + app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id); + app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id); + return $merchant; + }); + } + }