From 5cf43a6f596e53d3a7972b168cb0e079dc42e4df Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 21 Apr 2023 18:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/MerchantIntentionRepository.php | 4 +- .../system/merchant/MerchantRepository.php | 8 +- .../api/store/merchant/Merchant.php | 112 ++++++++++++++++++ 3 files changed, 119 insertions(+), 5 deletions(-) diff --git a/app/common/repositories/system/merchant/MerchantIntentionRepository.php b/app/common/repositories/system/merchant/MerchantIntentionRepository.php index c2550529..918f9f4c 100644 --- a/app/common/repositories/system/merchant/MerchantIntentionRepository.php +++ b/app/common/repositories/system/merchant/MerchantIntentionRepository.php @@ -124,6 +124,9 @@ class MerchantIntentionRepository extends BaseRepository 'type_id' => $intention['mer_type_id'], 'real_name' => $intention['name'], 'status' => 1, + 'area_id' => $intention['area_id'], + 'street_id' => $intention['street_id'], + 'village_id' => $intention['village_id'], 'is_audit' => 1, 'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1, 'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1, @@ -148,7 +151,6 @@ class MerchantIntentionRepository extends BaseRepository 'site' => systemConfig('site_name'), ]; } - Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) { if ($data['status'] == 1) { if ($create) { diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 3ed6091b..103dfa68 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -253,10 +253,10 @@ class MerchantRepository extends BaseRepository $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']]); -// } + $address_id = Db::name('merchant_address')->insertGetId(['mer_id'=>$merchant->mer_id,'street_id'=>$data['street_id'],'area_id'=>$data['area_id'],'village_id'=>$data['village_id']]); + 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; diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 0719b505..28e8fb17 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -12,10 +12,18 @@ namespace app\controller\api\store\merchant; +use app\common\repositories\store\MerchantTakeRepository; +use app\common\repositories\store\product\ProductRepository; +use app\common\repositories\system\config\ConfigValueRepository; use app\common\repositories\user\UserMerchantRepository; +use app\validate\merchant\MerchantTakeValidate; +use app\validate\merchant\MerchantUpdateValidate; +use crmeb\jobs\ChangeMerchantStatusJob; use think\App; use crmeb\basic\BaseController; use app\common\repositories\system\merchant\MerchantRepository as repository; +use think\facade\Db; +use think\facade\Queue; class Merchant extends BaseController { @@ -118,5 +126,109 @@ class Merchant extends BaseController $where['delivery_way'] = 1; return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo)); } + /** + * @param MerchantUpdateValidate $validate + * @return mixed + * @author xaboy + * @day 2020/6/25 + */ + public function update(MerchantUpdateValidate $validate, MerchantTakeValidate $takeValidate, MerchantTakeRepository $repository) + { + + $type = $this->request->param('type',1); + $id = $this->request->param('id'); + if(empty($id)){ + return app('json')->fail('参数错误'); + } + + $merchant = Db::name('merchant')->where('mer_id',$id)->find(); + if ($type == 2) { + $data = $this->request->params([ + 'mer_info', + 'mer_certificate', + 'service_phone', + 'mer_avatar', + 'mer_banner', + 'mer_state', + 'mini_banner', + 'mer_keyword', + 'mer_address', + 'long', + 'lat', + ['delivery_way',[2]], + ]); + + // 如果手机号不存在,则使用入驻时的手机号 + $data['service_phone'] = empty($data['service_phone'])?$merchant['mer_phone']:$data['service_phone']; + + $validate->check($data); + $sys_bases_status = systemConfig('sys_bases_status') === '0' ? 0 : 1; + if ($sys_bases_status && empty($data['mer_certificate'])) + return app('json')->fail('店铺资质不可为空'); + + app()->make(ConfigValueRepository::class)->setFormData([ + 'mer_certificate' => $data['mer_certificate'] + ], $id); + unset($data['mer_certificate']); + + foreach ($data['delivery_way'] as $datum) { + if ($datum == 1) { + $takeData = $this->request->params(['mer_take_status', 'mer_take_location', 'mer_take_day', 'mer_take_time']); + $takeData['mer_take_name'] = $merchant['mer_name']; + $takeData['mer_take_address'] = $data['mer_address']; + $takeData['mer_take_phone'] = $merchant['mer_phone']; + $takeValidate->check($takeData); + $repository->set($id, $takeData); + break; + } + } + $delivery_way = implode(',',$data['delivery_way']); + if (count($data['delivery_way']) == 1 && $data['delivery_way'] != $merchant['delivery_way']) { + app()->make(ProductRepository::class)->getSearch([]) + ->where('mer_id',$merchant['mer_id']) + ->update(['delivery_way' => $delivery_way]); + } + + $data['delivery_way'] = $delivery_way; + + } else { + $data = $this->request->params(['mer_state']); + + if ($merchant['is_margin'] == 1 && $data['mer_state'] == 1) + return app('json')->fail('开启店铺前请先支付保证金'); + + if ($data['mer_state'] && !$merchant['sub_mchid'] && systemConfig('open_wx_combine')) + return app('json')->fail('开启店铺前请先完成微信子商户入驻'); + } + Db::name('merchant')->where('mer_id',$id)->update($data); + + Queue::push(ChangeMerchantStatusJob::class, $id); + return app('json')->success('修改成功'); + } + + /** + * @return mixed + * @author xaboy + * @day 2020/7/21 + */ + public function info(MerchantTakeRepository $repository) + { + $id = $this->request->param('id'); + if(empty($id)){ + return app('json')->fail('参数错误'); + } + + $data = Db::name('merchant')->where('mer_id',$id)->find(); + // $append = ['merchantCategory', 'merchantType', 'mer_certificate']; + // if ($merchant['is_margin'] == -10) + // $append[] = 'refundMarginOrder'; + + // $data = $merchant->append($append)->hidden(['mark', 'reg_admin_id', 'sort'])->toArray(); + $delivery = $repository->get($id) + systemConfig(['tx_map_key']); + $data = array_merge($data,$delivery); + $data['sys_bases_status'] = systemConfig('sys_bases_status') === '0' ? 0 : 1; + + return app('json')->success($data); + } }