From b70ddddbbc9b5f88dfd957c2824b4be37664cab8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 4 Dec 2023 16:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/store/merchant/Merchant.php | 150 +++++++++--------- 1 file changed, 74 insertions(+), 76 deletions(-) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index d1a176ba..559e979d 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -47,7 +47,7 @@ class Merchant extends BaseController { parent::__construct($app); $this->repository = $repository; - $this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null; + $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null; } /** @@ -58,21 +58,21 @@ class Merchant extends BaseController public function lst() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['store_category_id','keyword', 'order', 'is_best', 'location', 'category_id', 'type_id', 'type_code', 'is_trader', 'street_id', 'credit_buy']); + $where = $this->request->params(['merchant_category_id', 'keyword', 'order', 'is_best', 'location', 'category_id', 'type_id', 'type_code', 'is_trader', 'street_id', 'credit_buy']); if (empty($where['type_id'])) { - $where['type_id'] =[10,17]; + $where['type_id'] = [10, 17]; } - if($where['store_category_id']>0){ - $arr= Db::name('store_category')->where(['pid'=>$where['store_category_id'],'mer_id'=>0,'level'=>1,'is_show'=>1])->column('cate_name'); - if($arr){ - $category_id=Db::name('merchant_category')->whereIn('category_name',$arr)->column('merchant_category_id'); - if($category_id){ - $where['category_id']=implode(',',$category_id); - } - } - unset($where['store_category_id']); + if ($where['merchant_category_id'] > 0) { + // $arr= Db::name('store_category')->where(['pid'=>$where['store_category_id'],'mer_id'=>0,'level'=>1,'is_show'=>1])->column('cate_name'); + // if($arr){ + // $category_id=Db::name('merchant_category')->whereIn('category_name',$arr)->column('merchant_category_id'); + // if($category_id){ + // $where['category_id']=implode(',',$category_id); + // } + // } + $where['category_id'] = $where['merchant_category_id']; + unset($where['merchant_category_id']); } - // $where['category_id']=$where['store_category_id']??''; return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo)); } @@ -96,7 +96,7 @@ class Merchant extends BaseController public function systemDetail() { - $config = systemConfig(['site_logo', 'site_name','login_logo']); + $config = systemConfig(['site_logo', 'site_name', 'login_logo']); return app('json')->success([ 'mer_avatar' => $config['login_logo'], 'mer_name' => $config['site_name'], @@ -115,9 +115,9 @@ class Merchant extends BaseController public function productList($id) { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['keyword','order','mer_cate_id','cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid']); - if(!$this->repository->apiGetOne($id)) return app('json')->fail(' 店铺已打烊'); - return app('json')->success($this->repository->productList($id,$where, $page, $limit,$this->userInfo)); + $where = $this->request->params(['keyword', 'order', 'mer_cate_id', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid']); + if (!$this->repository->apiGetOne($id)) return app('json')->fail(' 店铺已打烊'); + return app('json')->success($this->repository->productList($id, $where, $page, $limit, $this->userInfo)); } /** @@ -128,35 +128,34 @@ class Merchant extends BaseController */ public function categoryList($id) { - if(!$this->repository->merExists((int)$id)) + if (!$this->repository->merExists((int)$id)) return app('json')->fail('店铺已打烊'); return app('json')->success($this->repository->categoryList($id)); } public function qrcode($id) { - if(!$this->repository->merExists($id)) + if (!$this->repository->merExists($id)) return app('json')->fail('店铺已打烊'); - if ($this->request->param('type') == 'routine') { - $url= $this->repository->routineQrcode(intval($id)); - }elseif($this->request->param('type') == 'app'){ + if ($this->request->param('type') == 'routine') { + $url = $this->repository->routineQrcode(intval($id)); + } elseif ($this->request->param('type') == 'app') { $attachmentRepository = app()->make(AttachmentRepository::class); - $name='merchant_code_'.$id.'.png'; + $name = 'merchant_code_' . $id . '.png'; $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); - if($imageInfo){ - $url=$imageInfo['attachment_src']; - }else{ - $info = app()->make(QrcodeService::class)->getQRCodePath(systemConfig('site_url').'pages/store/home/index?id=' . $id, $name); + if ($imageInfo) { + $url = $imageInfo['attachment_src']; + } else { + $info = app()->make(QrcodeService::class)->getQRCodePath(systemConfig('site_url') . 'pages/store/home/index?id=' . $id, $name); $attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $id, [ 'attachment_category_id' => 0, 'attachment_name' => $info['name'], 'attachment_src' => $info['dir'] ]); - $url=$info['dir']; + $url = $info['dir']; } - } - else{ - $url= $this->repository->wxQrcode(intval($id)); + } else { + $url = $this->repository->wxQrcode(intval($id)); } return app('json')->success(compact('url')); } @@ -177,13 +176,13 @@ class Merchant extends BaseController public function update(MerchantUpdateValidate $validate, MerchantTakeValidate $takeValidate, MerchantTakeRepository $repository) { - $type = $this->request->param('type',1); + $type = $this->request->param('type', 1); $id = $this->request->param('id'); - if(empty($id)){ + if (empty($id)) { return app('json')->fail('参数错误'); } - $merchant = Db::name('merchant')->where('mer_id',$id)->find(); + $merchant = Db::name('merchant')->where('mer_id', $id)->find(); if ($type == 2) { $data = $this->request->params([ 'mer_info', @@ -197,17 +196,17 @@ class Merchant extends BaseController 'mer_address', 'long', 'lat', - ['delivery_way',[2]], + ['delivery_way', [2]], 'credit_buy', 'settle_cycle', 'interest_rate', ]); - if(empty($data['service_phone'])) { + if (empty($data['service_phone'])) { return app('json')->fail('客户电话不能为空'); } // 如果手机号不存在,则使用入驻时的手机号 - $data['service_phone'] = empty($data['service_phone'])?$merchant['mer_phone']:$data['service_phone']; + $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; @@ -216,7 +215,7 @@ class Merchant extends BaseController $merCertificate = merchantConfig($id, 'mer_certificate'); if (!is_array($merCertificate)) { - $merCertificate = explode( ',', $merCertificate); + $merCertificate = explode(',', $merCertificate); } $merCertificate[0] = $data['mer_certificate']; app()->make(ConfigValueRepository::class)->setFormData([ @@ -235,15 +234,14 @@ class Merchant extends BaseController break; } } - $delivery_way = implode(',',$data['delivery_way']); + $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']) + ->where('mer_id', $merchant['mer_id']) ->update(['delivery_way' => $delivery_way]); } $data['delivery_way'] = $delivery_way; - } else { $data = $this->request->params(['mer_state']); @@ -253,7 +251,7 @@ class Merchant extends BaseController if ($data['mer_state'] && !$merchant['sub_mchid'] && systemConfig('open_wx_combine')) return app('json')->fail('开启店铺前请先完成微信子商户入驻'); } - Db::name('merchant')->where('mer_id',$id)->update($data); + Db::name('merchant')->where('mer_id', $id)->update($data); Queue::push(ChangeMerchantStatusJob::class, $id); return app('json')->success('修改成功'); @@ -267,11 +265,11 @@ class Merchant extends BaseController public function info(MerchantTakeRepository $repository) { $id = $this->request->param('id'); - if(empty($id)){ + if (empty($id)) { return app('json')->fail('参数错误'); } - $data = Db::name('merchant')->where('mer_id',$id)->find(); + $data = Db::name('merchant')->where('mer_id', $id)->find(); $data['mer_certificate'] = merchantConfig($id, 'mer_certificate'); $data['mer_certificate'] = $data['mer_certificate'][0] ?? ''; // $append = ['merchantCategory', 'merchantType', 'mer_certificate']; @@ -280,7 +278,7 @@ class Merchant extends BaseController // $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 = array_merge($data, $delivery); $data['sys_bases_status'] = systemConfig('sys_bases_status') === '0' ? 0 : 1; $data['type_code'] = Db::name('MerchantType')->where('mer_type_id', $data['type_id'])->value('type_code'); return app('json')->success($data); @@ -294,46 +292,47 @@ class Merchant extends BaseController public function marginInfo(MerchantTakeRepository $repository) { $id = $this->request->param('id'); - if(empty($id)){ + if (empty($id)) { return app('json')->fail('参数不能为空'); } - $merchantInfo = Db::name('merchant')->where('mer_id',$id)->field('uid,mer_id,type_id,mer_name,margin,paid_margin,is_margin')->find(); - if(empty($merchantInfo)){ + $merchantInfo = Db::name('merchant')->where('mer_id', $id)->field('uid,mer_id,type_id,mer_name,margin,paid_margin,is_margin')->find(); + if (empty($merchantInfo)) { return app('json')->fail('参数错误'); } $margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin'); - $merchantInfo['unpaid_margin'] = bcsub($margin,$merchantInfo['paid_margin'],2); - if($merchantInfo['margin']==0){ - $merchantInfo['margin']=$merchantInfo['unpaid_margin']; + $merchantInfo['unpaid_margin'] = bcsub($margin, $merchantInfo['paid_margin'], 2); + if ($merchantInfo['margin'] == 0) { + $merchantInfo['margin'] = $merchantInfo['unpaid_margin']; } return app('json')->success($merchantInfo); } - public function apply($merId){ + public function apply($merId) + { $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); } $extract_minimum_line = systemConfig('extract_minimum_line') ?: 0; $extract_minimum_num = systemConfig('extract_minimum_num'); - $_line = bcsub($merchant->mer_money,$extract_minimum_line,2); + $_line = bcsub($merchant->mer_money, $extract_minimum_line, 2); $_extract = ($_line < 0) ? 0 : $_line; $merLockMoney = app()->make(UserBillRepository::class)->merchantLickMoney($merId); $data = [ - 'mer_id' => $merchant->mer_id,//商户id - 'mer_name' => $merchant->mer_name,//商户名称 - 'mer_money' => $merchant->mer_money,//商户余额 - 'lock_money' => $merLockMoney,//冻结金额 - 'lock_time' => systemConfig('mer_lock_time'),//冻结金额 - 'extract_minimum_line' => $extract_minimum_line,//提现最低额度 - 'extract_minimum_num' => $extract_minimum_num,//提现最低次数 - 'extract_money' => $_extract,//可提现金额 - 'financial_bank_name' => $merchant->financial_bank->name ?? '',//银行卡信息 - 'financial_bank_bank' => $merchant->financial_bank->bank ?? '',//银行卡信息 - 'financial_bank_code' => $merchant->financial_bank->bank_code ?? '',//银行卡信息 - 'financial_bank_branch' => $merchant->financial_bank->bank_branch ?? '',//开户行 - 'financial_type' => $merchant->financial_type,//提现方式 + 'mer_id' => $merchant->mer_id, //商户id + 'mer_name' => $merchant->mer_name, //商户名称 + 'mer_money' => $merchant->mer_money, //商户余额 + 'lock_money' => $merLockMoney, //冻结金额 + 'lock_time' => systemConfig('mer_lock_time'), //冻结金额 + 'extract_minimum_line' => $extract_minimum_line, //提现最低额度 + 'extract_minimum_num' => $extract_minimum_num, //提现最低次数 + 'extract_money' => $_extract, //可提现金额 + 'financial_bank_name' => $merchant->financial_bank->name ?? '', //银行卡信息 + 'financial_bank_bank' => $merchant->financial_bank->bank ?? '', //银行卡信息 + 'financial_bank_code' => $merchant->financial_bank->bank_code ?? '', //银行卡信息 + 'financial_bank_branch' => $merchant->financial_bank->bank_branch ?? '', //开户行 + 'financial_type' => $merchant->financial_type, //提现方式 ]; return app('json')->success($data); } @@ -346,7 +345,7 @@ class Merchant extends BaseController */ public function createApply($merId) { - $data = $this->request->param(['extract_money','financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']); + $data = $this->request->param(['extract_money', 'financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']); $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); @@ -360,7 +359,7 @@ class Merchant extends BaseController $merchant->update(['financial_bank' => json_encode($bankInfo, JSON_UNESCAPED_UNICODE)], ['mer_id' => $merId]); $data['mer_admin_id'] = $merchant['reg_admin_id']; unset($data['financial_bank_name'], $data['financial_bank_bank'], $data['financial_bank_code'], $data['financial_bank_branch']); - app()->make(FinancialRepository::class)->saveApply($merId,$data); + app()->make(FinancialRepository::class)->saveApply($merId, $data); return app('json')->success('申请成功'); } @@ -372,9 +371,8 @@ class Merchant extends BaseController } [$page, $limit] = $this->getPage(); $where['mer_id'] = $merId; - $data = app()->make(FinancialRepository::class)->getAdminList($where,$page,$limit); + $data = app()->make(FinancialRepository::class)->getAdminList($where, $page, $limit); return app('json')->success($data); - } public function account($merId) @@ -384,17 +382,17 @@ class Merchant extends BaseController return app('json')->fail($msg); } $data = [ - 'financial_bank' => $merchant->financial_bank,//银行卡信息 - 'financial_wechat' => $merchant->financial_wechat,//微信信息 - 'financial_alipay' => $merchant->financial_alipay,//支付宝信息 - 'financial_type' => $merchant->financial_type,//提现方式 + 'financial_bank' => $merchant->financial_bank, //银行卡信息 + 'financial_wechat' => $merchant->financial_wechat, //微信信息 + 'financial_alipay' => $merchant->financial_alipay, //支付宝信息 + 'financial_type' => $merchant->financial_type, //提现方式 ]; return app('json')->success($data); } public function account_info($merId) { - $data = $this->request->param(['name','bank','bank_code','financial_type']); + $data = $this->request->param(['name', 'bank', 'bank_code', 'financial_type']); app()->make(MerchantFinancialAccountValidate::class)->check($data); $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); if (($msg = $this->checkAuth($merchant)) !== true) { @@ -405,7 +403,7 @@ class Merchant extends BaseController 'bank' => $data['bank'], 'bank_code' => $data['bank_code'], ]; - app()->make(MerchantRepository::class)->update($merId,['financial_bank' => json_encode($update),'financial_type' => 1]); + app()->make(MerchantRepository::class)->update($merId, ['financial_bank' => json_encode($update), 'financial_type' => 1]); return app('json')->success('提交成功'); }