diff --git a/app/common/repositories/store/MerchantTakeRepository.php b/app/common/repositories/store/MerchantTakeRepository.php index 452576d4..b613e06f 100644 --- a/app/common/repositories/store/MerchantTakeRepository.php +++ b/app/common/repositories/store/MerchantTakeRepository.php @@ -21,7 +21,7 @@ class MerchantTakeRepository public function get($merId) { return merchantConfig($merId, [ - 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time' + 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time','mer_certificate' ]); } diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 090d0fdd..8a40eab0 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -313,6 +313,8 @@ class MerchantRepository extends BaseRepository $item['recommend'] = isset($where['delivery_way']) ? $item['CityRecommend'] : $item['AllRecommend']; $item['area_name'] = Db::name('merchant_address')->alias('a')->join('eb_geo_area b','a.area_id=b.area_code')->where('a.mer_id',$item['mer_id'])->value('b.area_name')??''; $item['street_name'] = Db::name('merchant_address')->alias('a')->join('eb_geo_street b','a.street_id=b.street_code')->where('a.mer_id',$item['mer_id'])->value('b.street_name'); +// 查询优惠券 + $item['store_coupon'] = Db::name('store_coupon')->where('mer_id',$item['mer_id'])->where('is_del',0)->column('title'); return $item; }); diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 718440f3..a36364bd 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -170,6 +170,17 @@ class Auth extends BaseController } // 新增返回商户后台登录地址 $data['merchant_login'] = $this->request->domain().'/merchant'; +// 判断是否是商户,并且有没有完善信息 + $mer_arr = Db::name('merchant_intention')->alias('a')->join('merchant b','a.mer_id=b.mer_id')->where('a.uid',$data['uid'])->where('a.is_del',0)->where('a.status',1)->field('b.mer_avatar,b.mer_banner,b.mer_info,b.service_phone,b.mer_address')->find(); + if($mer_arr){ + if (!$mer_arr['mer_avatar'] || !$mer_arr['mer_banner'] || !$mer_arr['mer_info'] || !$mer_arr['service_phone'] || !$mer_arr['mer_address']) { + $data['is_wsxx'] = 0; + }else{ + $data['is_wsxx'] = 1; + } + }else{ + $data['is_wsxx'] = 0; + } return app('json')->success($data); } diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index ba309f0b..99aa81fc 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -12,10 +12,19 @@ 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\Queue; +use think\facade\Db; + class Merchant extends BaseController { @@ -119,4 +128,106 @@ class Merchant extends BaseController 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]], + ]); + $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); + } + + } diff --git a/route/api.php b/route/api.php index 8ecd2d5b..59e037fe 100644 --- a/route/api.php +++ b/route/api.php @@ -494,6 +494,10 @@ Route::group('api/', function () { Route::get('/detail/:id', 'Merchant/detail'); Route::get('/qrcode/:id', 'Merchant/qrcode'); Route::get('/local', 'Merchant/localLst'); + //编辑商户信息 + Route::post('update', 'Merchant/update'); +// 商户信息 + Route::get('info', 'Merchant/info'); })->prefix('api.store.merchant.'); Route::post('store/certificate/:merId', 'api.Auth/getMerCertificate');