-
@@ -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;
+ });
+ }
+
}