同步老商城代码

This commit is contained in:
luofei 2024-03-12 15:27:46 +08:00
parent d503989cb0
commit 303bb16957
6 changed files with 518 additions and 35 deletions

View File

@ -12,6 +12,8 @@
namespace app\common\repositories\system\merchant;
use app\common\model\system\merchant\Merchant;
use app\common\model\system\merchant\MerchantCategory;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\config\ConfigValueRepository;
use crmeb\jobs\SendSmsJob;
@ -102,7 +104,12 @@ class MerchantIntentionRepository extends BaseRepository
public function updateStatus($id, $data)
{
$create = $data['create_mer'] == 1;
$data['create_mer'] = !empty($data['create_mer']) ? $data['create_mer'] : 2;
$create = ($data['create_mer'] == 1 || $data['create_mer'] == -1);
$autoCreate = 0;
if ($data['create_mer'] == -1) {
$autoCreate = 1;
}
unset($data['create_mer']);
$intention = $this->search(['mer_intention_id' => $id])->find();
if (!$intention)
@ -112,6 +119,7 @@ class MerchantIntentionRepository extends BaseRepository
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$margin = app()->make(MerchantTypeRepository::class)->get($intention['mer_type_id']);
$commissionRate = MerchantCategory::where('merchant_category_id', $intention['merchant_category_id'])->value('commission_rate');
$data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0;
$merData = [];
@ -133,7 +141,27 @@ class MerchantIntentionRepository extends BaseRepository
'is_margin' => $margin['is_margin'] ?? -1,
'margin' => $margin['margin'] ?? 0,
'mark' => $margin['margin'] ?? 0,
'mer_state' => 1, //审核通过自动开启
'area_id' => $intention['area_id'],
'street_id' => $intention['street_id'],
'village_id' => $intention['village_id'],
'uid' => $intention['uid'],
'reg_admin_id' => 0,
'mer_intention_id' => $id,
'is_company' => $intention['is_company'],
'business_status' => 2,
'mer_settlement_agree_status' => 1,
'commission_rate' => $commissionRate * 100,
'financial_bank' => $intention['financial_bank'],
];
if($margin['type_code']=='PersonalStore'){
$merData['mer_address']='集体地址';
$merData['mer_avatar']='https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png';
$merData['mer_banner']='https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png';
$merData['mini_banner']='https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png';
$merData['create_time']=date('Y-m-d H:i:s');
$merData['update_time']=date('Y-m-d H:i:s',time()+1);
}
$data['fail_msg'] = '';
$smsData = [
'date' => date('m月d日', strtotime($intention->create_time)),
@ -152,12 +180,43 @@ class MerchantIntentionRepository extends BaseRepository
];
}
Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) {
Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData,$autoCreate) {
if ($data['status'] == 1) {
if ($create == 1) {
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
app()->make(ConfigValueRepository::class)->setFormData(['mer_certificate' => $intention['images']], $merchant->mer_id);
if (!empty($intention['images'])) {
app()->make(ConfigValueRepository::class)->setFormData([
'mer_certificate' => $intention['images']
], $merchant->mer_id);
}
$data['mer_id'] = $merchant->mer_id;
$data['uid'] = $intention['uid'];
$data['reg_admin_id'] = $autoCreate ? 0: $merchant['merchant_admin']['merchant_admin_id'];
//写入商户客服表
$store_service_data['mer_id'] = $merchant->mer_id;
$store_service_data['uid'] = $intention['uid'];
$store_service_data['avatar'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/1b716202302251108516996.png';
$store_service_data['nickname'] = $intention['mer_name'];
$store_service_data['account'] = $intention['phone'];
$store_service_data['pwd'] = password_hash('123456', PASSWORD_BCRYPT);;
$store_service_data['status'] = 1;
$store_service_data['is_open'] = 1;
$store_service_data['notify'] = 1;
$store_service_data['customer'] = 1;
$store_service_data['is_verify'] = 1;
$store_service_data['is_goods'] = 1;
$store_service_data['phone'] = $intention['phone'];
$store_service_data['create_time'] = date('Y-m-d H:i:s');
Db::name('store_service')->insert($store_service_data);
}
if ($intention['type'] == 2) {
$merId = Merchant::where('uid', $intention['uid'])->value('mer_id');
if (!empty($merId)) {
Merchant::where('mer_id', $merId)->update(['business_status' => 2, 'mer_settlement_agree_status' => 1]);
}
}
if (!empty($smsData)) {
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
}
} else {

View File

@ -14,12 +14,20 @@
namespace app\controller\api;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\model\store\coupon\StoreCouponDetail;
use app\common\model\store\coupon\StoreCouponUser;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreOrderProduct;
use app\common\model\store\order\StoreOrderStatus;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\system\merchant\FinancialRecord;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\UserAddress;
use app\common\model\user\UserBill;
use app\common\model\user\UserRecharge;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository;
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\user\UserOrderRepository;
use app\common\repositories\user\UserRechargeRepository;
use app\common\repositories\user\UserRepository;
use app\common\repositories\user\UserSignRepository;
use app\common\repositories\wechat\RoutineQrcodeRepository;
@ -30,7 +38,6 @@ use crmeb\basic\BaseController;
use crmeb\services\MiniProgramService;
use crmeb\services\SmsService;
use crmeb\services\WechatService;
use crmeb\services\WechatTemplateMessageService;
use Exception;
use Firebase\JWT\JWT;
use Gregwar\Captcha\CaptchaBuilder;
@ -40,11 +47,10 @@ use Symfony\Component\HttpFoundation\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Log;
use think\facade\Queue;
use crmeb\jobs\SendSmsJob;
use think\facade\Db;
/**
* Class Auth
@ -763,4 +769,94 @@ class Auth extends BaseController
}
}
/**
* 合并账号
* @param UserRepository $repository
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function merge(UserRepository $repository)
{
$data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]);
$sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login');
if (!$sms_code && !env('APP_DEBUG')) {
return app('json')->fail('验证码不正确');
}
$auth = Cache::get('u_try' . $data['auth_token']);
$auth && Cache::delete('u_try' . $data['auth_token']);
if (empty($auth)) {
return app('json')->fail('授权已过期,请重新登录');
}
$user = $repository->wechatUserIdBytUser($auth['id']);
if (!empty($user['account']) && !empty($user['phone'])) {
return app('json')->fail('已绑定手机号');
}
$targetUser = $repository->accountByUser($data['phone']);
if (empty($targetUser)) {
if (!empty($user)) {
$user->account = $data['phone'];
$user->phone = $data['phone'];
$user->save();
$tokenInfo = $repository->createToken($user);
return app('json')->success($repository->returnToken($user, $tokenInfo));
} else {
$targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']);
$repository->bindSpread($targetUser, intval($data['spread']));
}
}
$repository->syncBaseAuth($auth, $targetUser);
if (!empty($user)) {
Db::startTrans();
try {
StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]);
UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreCouponUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreCouponDetail::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]);
if ($user->now_money > 0) {
$user->now_money = 0;
$targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2);
$targetUser->save();
}
$merchant = Merchant::where('uid', $targetUser['uid'])->find();
if (!empty($merchant)) {
$orders = StoreOrder::with(['refundOrder' => function(Query $query) {
$query->where('status', '<>', -1)->field('order_id,refund_price');
}])->where('uid', $user['uid'])
->whereIn('status', [0, 1, 2, 3, 9, 10])
->field('order_id,uid,total_price')
->select()->toArray();
$purchaseAmount = 0;
foreach ($orders as $order) {
$purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2);
foreach ($order['refundOrder']as $refundOrder) {
$purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2);
}
}
unset($refundOrder, $order);
if ($purchaseAmount > 0) {
$merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2);
$merchant->save();
}
}
$user->wechat_user_id = 0;
$user->save();
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
throw new ValidateException('绑定出错');
}
}
$tokenInfo = $repository->createToken($targetUser);
return app('json')->success($repository->returnToken($targetUser, $tokenInfo));
}
}

View File

@ -33,19 +33,21 @@ use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\user\UserRepository;
use app\common\repositories\user\UserSignRepository;
use app\common\repositories\user\UserVisitRepository;
use app\common\repositories\wechat\TemplateMessageRepository;
use app\common\repositories\wechat\WechatUserRepository;
use crmeb\basic\BaseController;
use crmeb\services\AlipayService;
use crmeb\services\CopyCommand;
use crmeb\services\MiniProgramService;
use crmeb\services\QrcodeService;
use crmeb\services\UploadService;
use crmeb\services\WechatService;
use Exception;
use Joypack\Tencent\Map\Bundle\Location;
use Joypack\Tencent\Map\Bundle\LocationOption;
use Overtrue\Pinyin\Pinyin;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use think\Response;
@ -565,4 +567,99 @@ class Common extends BaseController
$data['config'] = systemConfig(['open_screen_switch','open_screen_time','open_screen_space']);
return app('json')->success($data);
}
/**
* 生成二维码
*/
public function Qrcode($data)
{
$siteUrl = systemConfig('site_url');
$name = 'orcode'.$data['id'] .md5(date('code') . date('Ymd')) . '.png';
$attachmentRepository = app()->make(AttachmentRepository::class);
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
$imageInfo->delete();
$imageInfo = null;
}
if (!$imageInfo) {
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>1]);
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);
$attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $data['id'], [
'attachment_category_id' => 0,
'attachment_name' => $imageInfo['name'],
'attachment_src' => $imageInfo['dir']
]);
$urlCode = $imageInfo['dir'];
} else $urlCode = $imageInfo['attachment_src'];
return $urlCode;
}
/**
* 获取城市
* @param $code
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCity($code = 510000)
{
$select = Db::name('geo_city')->where('province_code', $code)->field('city_id id,city_code code,city_name name')->select();
return app('json')->success($select);
}
//区县数据
public function get_area($city_code = 510500)
{
$select = Db::name('geo_area')->where('city_code', $city_code)->field('area_id id,area_code code,area_name name')->select();
return app('json')->success($select);
}
//街道 乡镇数据
public function get_street($area_code)
{
$select = Db::name('geo_street')->where('area_code', $area_code)->field('street_id id,street_code code,street_name name')->select();
$arr = $select ? $select->toArray() : [];
foreach ($arr as $k => $item) {
$first_char = mb_str_split($item['name']);
if ($first_char[0]) {
$pinyin = new Pinyin();
$string = $first_char[0];
$pinyin = $pinyin->abbr($string);
$arr[$k]['pinyin'] = $pinyin;
} else {
$arr[$k]['pinyin'] = '';
}
}
return app('json')->success($arr);
}
//村数据
public function get_village($street_code)
{
$select = Db::name('geo_village')->where('street_code', $street_code)->field('village_id id,village_code code,village_name name')->select();
return app('json')->success($select);
}
/**
* 小程序版本
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function applet()
{
$group_id = Db::name('system_group')->where('group_key', 'applet')->value('group_id');
$list = [];
if ($group_id) {
$select = Db::name('system_group_data')->where('group_id', $group_id)->field('value')->limit(30)->where('status',1)->select();
foreach ($select as $key => $value) {
$list[] = json_decode($value['value'], true);
}
}
return app('json')->success($list);
}
}

View File

@ -12,6 +12,7 @@
namespace app\controller\api\store\merchant;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\system\merchant\MerchantAdminRepository;
use app\common\repositories\system\merchant\MerchantCategoryRepository;
use app\common\repositories\system\merchant\MerchantRepository;
@ -19,11 +20,12 @@ use app\common\repositories\system\merchant\MerchantTypeRepository;
use app\validate\api\MerchantIntentionValidate;
use crmeb\services\SmsService;
use crmeb\services\SwooleTaskService;
use crmeb\services\YunxinSmsService;
use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
class MerchantIntention extends BaseController
{
@ -44,6 +46,24 @@ class MerchantIntention extends BaseController
return app('json')->fail('未开启商户入驻');
}
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
if (($this->userInfo->phone ?? false) && ($this->userInfo->phone != ($data['phone'] ?? ''))) {
throw new ValidateException('联系电话和注册手机不一致');
}
$intentionInfo = Db::name('merchant_intention')
->where('social_credit_code', $data['social_credit_code'])
->where('status', '<>', 2)
->find();
if ($intentionInfo) {
throw new ValidateException('此统一社会信用代码已申请商户');
}
$merInfo = Db::name('merchant_intention')
->where('uid', $this->userInfo->uid)
->where('status', 'in', [0, 1])
->where('is_del', 0)
->find();
if ($merInfo) {
throw new ValidateException('该用户已申请商户,不可重复申请');
}
$make = app()->make(MerchantRepository::class);
if ($make->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名称已存在,不可申请');
@ -64,6 +84,190 @@ class MerchantIntention extends BaseController
return app('json')->success('提交成功');
}
/**
* 个人商户入驻
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function PersonalStore()
{
$data = $this->request->params([
'phone',
'mer_name',
'company_name',
'address',
'name',
'code',
'images',
'social_credit_code',
'city_id',
'area_id',
'street_id',
'village_id',
'is_nmsc',
'is_company',
'financial_bank'
]);
if (!empty($data['financial_bank'])) {
$data['financial_bank'] = json_encode($data['financial_bank']);
}
if (!systemConfig('mer_intention_open')) {
return app('json')->fail('未开启商户入驻');
}
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
if (($this->userInfo->phone ?? false) && ($this->userInfo->phone != ($data['phone'] ?? ''))) {
throw new ValidateException('联系电话和注册手机不一致');
}
$merInfo = Db::name('merchant_intention')->where('uid', $this->userInfo->uid)->where('status', 'in', [0, 1])->where('is_del', 0)->find();
if ($merInfo) {
throw new ValidateException('该用户已申请商户,不可重复申请');
}
$make = app()->make(MerchantRepository::class);
if ($make->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名称已存在,不可申请');
if ($make->fieldExists('mer_phone', $data['phone']))
throw new ValidateException('手机号已存在,不可申请');
$adminRepository = app()->make(MerchantAdminRepository::class);
if ($adminRepository->fieldExists('account', $data['phone']))
throw new ValidateException('手机号已是管理员,不可申请');
$mer_type_id = Db::name('merchant_type')->where('type_code', 'PersonalStore')->value('mer_type_id');
$data['status'] = 0;
$data['type'] = 2;
$data['mer_type_id'] = $mer_type_id;
$data['merchant_category_id'] = 2584;
$intention = $this->repository->create($data);
if ($intention) {
$datas['fail_msg'] = '';
$datas['create_mer'] = 1;
$datas['status'] = 1;
$this->repository->updateStatus($intention->mer_intention_id, $datas);
return app('json')->success('开户成功');
} else {
return app('json')->fail('开户失败');
}
}
public function settlementApply()
{
$status = $this->request->post('status', 0);
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
if ($status == 1) {
Db::name('merchant')->where('uid', $this->userInfo->uid)->update(['mer_settlement_agree_status' => 1]);
}
return app('json')->success('操作成功');
}
public function businessApply()
{
$data = $this->request->params([
'phone',
'mer_name',
'company_name',
'address',
'name',
'code',
'images',
'merchant_category_id',
'mer_type_id',
'social_credit_code',
'city_id',
'area_id',
'street_id',
'village_id',
'is_nmsc',
'bank_username',
'bank_code',
'bank_opening',
'bank_front',
'bank_back',
'cardno_front',
'cardno_back',
]);
if (empty($data['bank_username']) || empty($data['bank_opening']) || empty($data['bank_code'])) {
return app('json')->fail('请完善银行卡及身份信息');
}
if (!systemConfig('mer_intention_open')) {
return app('json')->fail('未开启商户入驻');
}
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
$settleIn = $this->repository->getWhere(['type' => 1, 'uid' => $data['uid'], 'is_del' => 0]);
$merchant = Merchant::where('uid', $data['uid'])->where('is_del', 0)->find();
if (empty($settleIn) && empty($merchant)) {
return app('json')->fail('请申请商户入驻申请!');
}
if (!empty($settleIn) && $settleIn['status'] == 0) {
return app('json')->fail('请等待商户入驻申请审核!');
}
$merIntentionInfo = $this->repository->getWhere(['type' => 2, 'uid' => $data['uid'], 'is_del' => 0]);
if (!empty($merIntentionInfo) && ($merIntentionInfo['status'] == 0)) {
return app('json')->fail('商户交易已申请,正在审核中!');
}
if (!empty($merIntentionInfo) && ($merIntentionInfo['status'] == 1)) {
return app('json')->fail('商户交易申请已通过');
}
$intenInfo['phone'] = $merchant['mer_phone'];
$intenInfo['mer_name'] = $merchant['mer_name'];
$intenInfo['company_name'] = $merchant['mer_name'];
$intenInfo['name'] = $merchant['real_name'];
$intenInfo['social_credit_code'] = '';
$intenInfo['images'] = [];
$intenInfo['merchant_category_id'] = $merchant['category_id'];
$intenInfo['mer_type_id'] = $merchant['type_id'];
$intenInfo['city_id'] = $merchant['city_id'];
$intenInfo['area_id'] = $merchant['area_id'];
$intenInfo['street_id'] = $merchant['street_id'];
$intenInfo['village_id'] = $merchant['village_id'];
$intenInfo['is_nmsc'] = $merchant['is_nmsc'];
$intenInfo['address'] = $merchant['mer_address'];
$intenInfo['bank_username'] = $data['bank_username'];
$intenInfo['bank_opening'] = $data['bank_opening'];
$intenInfo['bank_code'] = $data['bank_code'];
$intenInfo['bank_front'] = $data['bank_front'];
$intenInfo['bank_back'] = $data['bank_back'];
$intenInfo['cardno_front'] = $data['cardno_front'];
$intenInfo['cardno_back'] = $data['cardno_back'];
$intenInfo['uid'] = $data['uid'];
$intenInfo['type'] = 2;
$intenInfo['status'] = 0;
$intenInfo['create_time'] = date('Y-m-d H:i:s');
$this->repository->create($intenInfo);
return app('json')->success('申请成功');
}
//发送商户申请
public function sendMerIntentionApply($data, $postUrl)
{
Log::info("商户申请URL: {$postUrl}");
Log::info("发送商户申请信息: " . json_encode($data));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$resData = curl_exec($ch);
curl_close($ch);
$rtnData = [
'ok' => false,
'msg' => ''
];
if (!empty($resData) && is_string($resData)) {
Log::info("商户申请反馈信息" . $resData);
$resInfo = json_decode($resData, true);
if (!empty($resInfo['code']) && $resInfo['code'] == 1) {
$rtnData['ok'] = true;
} else {
$rtnData['msg'] = $resInfo['msg'];
}
}
return $rtnData;
}
public function update($id)
{
if (!$this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0]))
@ -106,12 +310,40 @@ class MerchantIntention extends BaseController
protected function checkParams()
{
$data = $this->request->params(['phone', 'mer_name', 'name', 'code', 'images', 'merchant_category_id', 'mer_type_id']);
$data = $this->request->params([
'phone',
'mer_name',
'company_name',
'address',
'name',
'code',
'images',
'mer_type_id',
'merchant_category_id',
'social_credit_code',
'city_id',
'area_id',
'street_id',
'village_id',
'is_nmsc',
'is_company',
'bank_username',
'bank_code',
'bank_opening',
'bank_front',
'bank_back',
'cardno_front',
'cardno_back',
'financial_bank',
]);
if (!empty($data['financial_bank'])) {
$data['financial_bank'] = json_encode($data['financial_bank']);
}
app()->make(MerchantIntentionValidate::class)->check($data);
$check = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['code'], 'intention');
$data['mer_type_id'] = (int)$data['mer_type_id'];
if (!$check) throw new ValidateException('验证码不正确');
if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
// if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id']))
throw new ValidateException('店铺类型不存在');
unset($data['code']);

View File

@ -553,28 +553,23 @@ class User extends BaseController
public function merchantRecord()
{
[$page, $limit] = $this->getPage();
$userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid');
$query = Merchant::whereIn('uid', $userIds)
->where('status', 1)
->where('is_del', 0)
->where('mer_state', 1);
$count = $query->count();
$result = $query->page($page, $limit)
->field('mer_id,mer_name,uid,real_name')
$userIds = UserModel::where('spread_uid', $this->user->uid)->page($page, $limit)->column('uid');
$query = Merchant::whereIn('uid', $userIds)->where('is_del', 0);
$merchants = $query->page($page, $limit)
->field('mer_id,mer_name,uid,real_name,sale_amount,purchase_amount as buy_amount')
->select()->toArray();
$dao = new StoreOrderDao();
/** @var PresellOrderRepository $preSellDao */
$preSellRepo = app()->make(PresellOrderRepository::class);
foreach ($result as &$item) {
$saleOrderQuery = $dao->search(['mer_id' => $item['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1);
$saleOrderIds = $saleOrderQuery->column('order_id');
$saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price');
$saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price');
$item['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2);
$item['buy_amount'] = StoreOrderOther::where('uid', $item['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price');
$item['buy_amount'] = bcadd($item['buy_amount'], 0, 2);
$merchants = reset_index($merchants, 'uid');
$result = [];
foreach ($userIds as $userId) {
if (isset($merchants[$userId])) {
$merchant = $merchants[$userId];
$merchant['status'] = 1;
$result[] = $merchant;
} else {
$result[] = ['mer_id' => '', 'mer_name' => '', 'uid' => $userId, 'real_name' => '', 'sale_amount' => '0.00', 'buy_amount' => '0.00', 'status' => 0];
}
}
return app('json')->success(['count' => $count, 'list' => $result]);
return app('json')->success(['count' => count($userIds), 'list' => $result]);
}
/**
@ -582,8 +577,11 @@ class User extends BaseController
*/
public function qrcode()
{
if ($this->user->is_promoter != 1) {
return app('json')->fail('您不是推广员');
}
/** @var Common $common */
$common = app()->make(Common::class);
$common= app()->make(Common::class);
$siteUrl = systemConfig('site_url');
$data = $common->Qrcode(['code' => $siteUrl . 'download/index.html?code=shop_' . $this->user->uid, 'id' => $this->user->uid]);
return app('json')->success(['url' => $data]);

1
public/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
runtime