2023-05-10 13:38:51 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace app\controller\api\store\merchant;
|
|
|
|
|
|
2023-07-12 16:43:02 +08:00
|
|
|
|
use app\common\model\store\order\StoreOrderInterest;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
use app\common\repositories\store\MerchantTakeRepository;
|
|
|
|
|
use app\common\repositories\store\product\ProductRepository;
|
|
|
|
|
use app\common\repositories\system\config\ConfigValueRepository;
|
|
|
|
|
use app\common\repositories\system\financial\FinancialRepository;
|
|
|
|
|
use app\common\repositories\system\merchant\MerchantRepository;
|
|
|
|
|
use app\common\repositories\user\UserMerchantRepository;
|
|
|
|
|
use app\validate\merchant\MerchantFinancialAccountValidate;
|
|
|
|
|
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;
|
2023-06-05 16:05:49 +08:00
|
|
|
|
use app\common\model\system\merchant\Merchant as MerchantModel;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
|
|
|
|
|
class Merchant extends BaseController
|
|
|
|
|
{
|
|
|
|
|
protected $repository;
|
|
|
|
|
protected $userInfo;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ProductCategory constructor.
|
|
|
|
|
* @param App $app
|
|
|
|
|
* @param repository $repository
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(App $app, repository $repository)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($app);
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
|
$this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/5/27
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function lst()
|
|
|
|
|
{
|
|
|
|
|
[$page, $limit] = $this->getPage();
|
2023-09-04 15:59:56 +08:00
|
|
|
|
$where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id', 'type_code', 'is_trader', 'street_id', 'credit_buy']);
|
2023-06-06 17:00:44 +08:00
|
|
|
|
if (empty($where['type_id'])) {
|
2023-08-31 09:39:46 +08:00
|
|
|
|
//$where['type_id'] = [MerchantModel::TypeCloudWarehouse, MerchantModel::TypeStore, MerchantModel::TypeSupplyChain, MerchantModel::TypePlatform];
|
2023-09-04 12:49:08 +08:00
|
|
|
|
$where['type_id'] = Db::name('MerchantType')->where('is_allow_apply', 1)->where('type_code', '<>', MerchantModel::TypeCode['TypeSupplyChain'])->column('mer_type_id');
|
2023-06-06 17:00:44 +08:00
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/5/29
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function detail($id)
|
|
|
|
|
{
|
|
|
|
|
if (!$this->repository->apiGetOne($id))
|
|
|
|
|
return app('json')->fail('店铺已打烊');
|
|
|
|
|
|
|
|
|
|
if ($this->request->isLogin()) {
|
|
|
|
|
app()->make(UserMerchantRepository::class)->updateLastTime($this->request->uid(), intval($id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app('json')->success($this->repository->detail($id, $this->userInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function systemDetail()
|
|
|
|
|
{
|
|
|
|
|
$config = systemConfig(['site_logo', 'site_name','login_logo']);
|
|
|
|
|
return app('json')->success([
|
|
|
|
|
'mer_avatar' => $config['login_logo'],
|
|
|
|
|
'mer_name' => $config['site_name'],
|
|
|
|
|
'mer_id' => 0,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/5/29
|
|
|
|
|
* @param $id
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/5/29
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function categoryList($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))
|
|
|
|
|
return app('json')->fail('店铺已打烊');
|
|
|
|
|
$url = $this->request->param('type') == 'routine' ? $this->repository->routineQrcode(intval($id)) : $this->repository->wxQrcode(intval($id));
|
|
|
|
|
return app('json')->success(compact('url'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function localLst()
|
|
|
|
|
{
|
|
|
|
|
[$page, $limit] = $this->getPage();
|
|
|
|
|
$where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id']);
|
|
|
|
|
$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]],
|
2023-07-10 10:58:37 +08:00
|
|
|
|
'credit_buy',
|
|
|
|
|
'settle_cycle',
|
|
|
|
|
'interest_rate',
|
2023-05-10 13:38:51 +08:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 如果手机号不存在,则使用入驻时的手机号
|
|
|
|
|
$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('店铺资质不可为空');
|
|
|
|
|
|
2023-05-31 17:38:47 +08:00
|
|
|
|
$merCertificate = merchantConfig($id, 'mer_certificate');
|
|
|
|
|
if (!is_array($merCertificate)) {
|
|
|
|
|
$merCertificate = explode( ',', $merCertificate);
|
|
|
|
|
}
|
|
|
|
|
$merCertificate[0] = $data['mer_certificate'];
|
2023-05-10 13:38:51 +08:00
|
|
|
|
app()->make(ConfigValueRepository::class)->setFormData([
|
2023-05-31 17:38:47 +08:00
|
|
|
|
'mer_certificate' => $merCertificate
|
2023-05-10 13:38:51 +08:00
|
|
|
|
], $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();
|
2023-05-31 17:38:47 +08:00
|
|
|
|
$data['mer_certificate'] = merchantConfig($id, 'mer_certificate');
|
|
|
|
|
$data['mer_certificate'] = $data['mer_certificate'][0] ?? '';
|
2023-05-10 13:38:51 +08:00
|
|
|
|
// $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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function apply($merId){
|
2023-07-13 11:42:10 +08:00
|
|
|
|
$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();
|
2023-07-07 11:24:00 +08:00
|
|
|
|
if (($msg = $this->checkAuth($merchant)) !== true) {
|
|
|
|
|
return app('json')->fail($msg);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
$extract_minimum_line = systemConfig('extract_minimum_line') ?: 0;
|
|
|
|
|
$extract_minimum_num = systemConfig('extract_minimum_num');
|
|
|
|
|
$_line = bcsub($merchant->mer_money,$extract_minimum_line,2);
|
|
|
|
|
$_extract = ($_line < 0) ? 0 : $_line;
|
|
|
|
|
$data = [
|
|
|
|
|
'mer_id' => $merchant->mer_id,//商户id
|
|
|
|
|
'mer_name' => $merchant->mer_name,//商户名称
|
|
|
|
|
'mer_money' => $merchant->mer_money,//商户余额
|
|
|
|
|
'extract_minimum_line' => $extract_minimum_line,//提现最低额度
|
|
|
|
|
'extract_minimum_num' => $extract_minimum_num,//提现最低次数
|
|
|
|
|
'extract_money' => $_extract,//可提现金额
|
2023-06-13 14:33:55 +08:00
|
|
|
|
'financial_bank_name' => $merchant->financial_bank->name ?? '',//银行卡信息
|
|
|
|
|
'financial_bank_bank' => $merchant->financial_bank->bank ?? '',//银行卡信息
|
|
|
|
|
'financial_bank_code' => $merchant->financial_bank->bank_code ?? '',//银行卡信息
|
2023-06-13 16:37:21 +08:00
|
|
|
|
'financial_bank_branch' => $merchant->financial_bank->bank_branch ?? '',//开户行
|
2023-05-10 13:38:51 +08:00
|
|
|
|
'financial_type' => $merchant->financial_type,//提现方式
|
|
|
|
|
];
|
|
|
|
|
return app('json')->success($data);
|
|
|
|
|
}
|
2023-06-13 16:37:21 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交提现申请
|
|
|
|
|
* @param $merId
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \FormBuilder\exception\FormBuilderException
|
|
|
|
|
*/
|
2023-05-10 13:38:51 +08:00
|
|
|
|
public function createApply($merId)
|
|
|
|
|
{
|
2023-06-13 16:37:21 +08:00
|
|
|
|
$data = $this->request->param(['extract_money','financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']);
|
2023-07-13 11:42:10 +08:00
|
|
|
|
$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();
|
2023-07-12 16:43:02 +08:00
|
|
|
|
if (($msg = $this->checkAuth($merchant)) !== true) {
|
2023-07-07 11:24:00 +08:00
|
|
|
|
return app('json')->fail($msg);
|
2023-07-04 14:39:52 +08:00
|
|
|
|
}
|
2023-06-13 16:37:21 +08:00
|
|
|
|
$bankInfo = [
|
|
|
|
|
'name' => $data['financial_bank_name'],
|
|
|
|
|
'bank' => $data['financial_bank_bank'],
|
|
|
|
|
'bank_code' => $data['financial_bank_code'],
|
|
|
|
|
'bank_branch' => $data['financial_bank_branch'],
|
|
|
|
|
];
|
|
|
|
|
$merchant->update(['financial_bank' => json_encode($bankInfo, JSON_UNESCAPED_UNICODE)], ['mer_id' => $merId]);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
$data['mer_admin_id'] = $merchant['reg_admin_id'];
|
2023-06-13 16:37:21 +08:00
|
|
|
|
unset($data['financial_bank_name'], $data['financial_bank_bank'], $data['financial_bank_code'], $data['financial_bank_branch']);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
app()->make(FinancialRepository::class)->saveApply($merId,$data);
|
|
|
|
|
return app('json')->success('申请成功');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function listApply($merId)
|
|
|
|
|
{
|
2023-07-13 11:42:10 +08:00
|
|
|
|
$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();
|
2023-07-12 16:43:02 +08:00
|
|
|
|
if (($msg = $this->checkAuth($merchant)) !== true) {
|
2023-07-07 11:24:00 +08:00
|
|
|
|
return app('json')->fail($msg);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
[$page, $limit] = $this->getPage();
|
|
|
|
|
$where['mer_id'] = $merId;
|
|
|
|
|
$data = app()->make(FinancialRepository::class)->getAdminList($where,$page,$limit);
|
|
|
|
|
return app('json')->success($data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function account($merId)
|
|
|
|
|
{
|
2023-07-13 11:42:10 +08:00
|
|
|
|
$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();
|
2023-07-12 16:43:02 +08:00
|
|
|
|
if (($msg = $this->checkAuth($merchant)) !== true) {
|
2023-07-07 11:24:00 +08:00
|
|
|
|
return app('json')->fail($msg);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
$data = [
|
|
|
|
|
'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']);
|
|
|
|
|
app()->make(MerchantFinancialAccountValidate::class)->check($data);
|
2023-07-13 11:42:10 +08:00
|
|
|
|
$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();
|
2023-07-12 16:43:02 +08:00
|
|
|
|
if (($msg = $this->checkAuth($merchant)) !== true) {
|
2023-07-07 11:24:00 +08:00
|
|
|
|
return app('json')->fail($msg);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
$update = [
|
|
|
|
|
'name' => $data['name'],
|
|
|
|
|
'bank' => $data['bank'],
|
|
|
|
|
'bank_code' => $data['bank_code'],
|
|
|
|
|
];
|
|
|
|
|
app()->make(MerchantRepository::class)->update($merId,['financial_bank' => json_encode($update),'financial_type' => 1]);
|
|
|
|
|
return app('json')->success('提交成功');
|
|
|
|
|
}
|
2023-07-07 11:24:00 +08:00
|
|
|
|
|
|
|
|
|
public function checkAuth($merchant)
|
|
|
|
|
{
|
|
|
|
|
if ($this->userInfo['uid'] != $merchant->uid) {
|
|
|
|
|
return '你不是管理员无法进行提现操作';
|
|
|
|
|
}
|
2023-07-15 16:10:52 +08:00
|
|
|
|
$unSettleCount = StoreOrderInterest::where('mer_id', $merchant->mer_id)->where('status', StoreOrderInterest::STATUS_UNSETTLED)->whereTime('start_time', '<=', time())->count();
|
2023-07-12 16:43:02 +08:00
|
|
|
|
if ($unSettleCount > 0) {
|
2023-07-07 11:24:00 +08:00
|
|
|
|
return '有未结清的订单,请结清订单后再进行提现';
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|