商户入驻申请审核功能完成

This commit is contained in:
liuxiaoquan 2023-03-13 17:31:53 +08:00
parent 3a94f7da5e
commit f716bf8d09
15 changed files with 252 additions and 279 deletions

View File

@ -53,7 +53,7 @@ Route::group(function(){
Route::get('lst', '/lst')->name('systemMerchantIntentionLst')->option([ Route::get('lst', '/lst')->name('systemMerchantIntentionLst')->option([
'_alias' => '列表', '_alias' => '列表',
]); ]);
Route::post('status', '/switchStatus')->name('systemMerchantIntentionStatus')->option([ Route::get('status', '/switchStatus')->name('systemMerchantIntentionStatus')->option([
'_alias' => '审核', '_alias' => '审核',
]); ]);
Route::delete('delete', '/delete')->name('systemMerchantIntentionDelete')->option([ Route::delete('delete', '/delete')->name('systemMerchantIntentionDelete')->option([

View File

@ -124,7 +124,10 @@
<script type="text/html" id="toolbarDemo"></script> <script type="text/html" id="toolbarDemo"></script>
<script type="text/html" id="barDemo"> <script type="text/html" id="barDemo">
<div class="layui-btn-group"> <div class="layui-btn-group">
{{# if(d.status == 0 ){ }}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="status">审核</a> <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="status">审核</a>
{{# } }}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="mark">备注</a> <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="mark">备注</a>
<a class="layui-btn layui-btn-xs" lay-event="del">删除</a> <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</div> </div>
@ -205,7 +208,16 @@
field: 'status', field: 'status',
title: '状态', title: '状态',
align: 'center', align: 'center',
width: 150 width: 150,
templet: function(d){
if (d.status==0){
return '待审核'
}else if(d.status==1){
return '已审核'
}else if(d.status==2){
return '审核未通过'
}
}
}, { }, {
field: 'mark', field: 'mark',
title: '备注', title: '备注',
@ -237,12 +249,11 @@
//监听表格行工具事件 //监听表格行工具事件
table.on('tool(intention_list)', function (obj) { table.on('tool(intention_list)', function (obj) {
var data = obj.data; var data = obj.data;
// console.log(data); if (obj.event === 'mark') { //备注
if (obj.event === 'mark') {
tool.side('/admin/merchant/intention/markform?id=' + obj.data.mer_intention_id); tool.side('/admin/merchant/intention/markform?id=' + obj.data.mer_intention_id);
} else if (obj.event === 'status') { } else if (obj.event === 'status') { //审核
tool.side('/admin/merchant/intention/statusform?id=' + obj.data.mer_intention_id); tool.side('/admin/merchant/intention/statusform?id=' + obj.data.mer_intention_id);
} else if (obj.event === 'del') { } else if (obj.event === 'del') { //删除
layer.confirm('确定要删除该记录吗?', { layer.confirm('确定要删除该记录吗?', {
icon: 3, icon: 3,
title: '提示' title: '提示'

View File

@ -57,7 +57,7 @@
}, 1000); }, 1000);
} }
} }
tool.post('/admin/merchant/intention/status', data.field, callback); tool.get('/admin/merchant/intention/status', data.field, callback);
return false; return false;
}); });
} }

View File

@ -1,30 +1,18 @@
<?php <?php
// +---------------------------------------------------------------------- namespace app\common\model\merchant;
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
// 应用公共文件
use app\common\model\merchant\system\config\SystemConfigValue;
// use app\common\model\merchant\system\groupData\GroupData; // use app\common\model\merchant\system\groupData\GroupData;
// use crmeb\services\UploadService; // use crmeb\services\UploadService;
// use Swoole\Lock; // use Swoole\Lock;
use app\common\model\merchant\system\config\SystemConfigValue;
use think\db\BaseQuery; use think\db\BaseQuery;
if (!function_exists('isDebug')) { class Common {
function isDebug(): bool function isDebug(): bool
{ {
return !!env('APP_DEBUG'); return !!env('APP_DEBUG');
} }
}
if (!function_exists('formToData')) {
function formToData($form): array function formToData($form): array
{ {
$rule = $form->formRule(); $rule = $form->formRule();
@ -43,9 +31,6 @@ if (!function_exists('formToData')) {
$api = str_replace('.html', '', $api); $api = str_replace('.html', '', $api);
return compact('rule', 'action', 'method', 'title', 'config', 'api'); return compact('rule', 'action', 'method', 'title', 'config', 'api');
} }
}
if (!function_exists('getDistance')) {
function getDistance($lat1, $lng1, $lat2, $lng2) function getDistance($lat1, $lng1, $lat2, $lng2)
{ {
@ -59,9 +44,8 @@ if (!function_exists('getDistance')) {
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6371; $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6371;
return round($s, 1); return round($s, 1);
} }
}
/** /**
* 无线级分类处理 * 无线级分类处理
* *
* @param array $data 数据源 * @param array $data 数据源
@ -69,10 +53,7 @@ if (!function_exists('getDistance')) {
* @param string $fieldName 父级字段 * @param string $fieldName 父级字段
* @param string $childrenKey 子级字段名 * @param string $childrenKey 子级字段名
* @return array * @return array
* @author 张先生
* @date 2020-03-27
*/ */
if (!function_exists('formatCategory')) {
function formatCategory(array $data, string $idName = "id", string $fieldName = 'pid', $childrenKey = 'children') function formatCategory(array $data, string $idName = "id", string $fieldName = 'pid', $childrenKey = 'children')
{ {
$items = []; $items = [];
@ -89,9 +70,7 @@ if (!function_exists('formatCategory')) {
} }
return $result; return $result;
} }
}
if (!function_exists('formatTreeList')) {
function formatTreeList(&$options, $name, $pidName = 'pid', $pid = 0, $level = 0, &$data = []): array function formatTreeList(&$options, $name, $pidName = 'pid', $pid = 0, $level = 0, &$data = []): array
{ {
$_options = $options; $_options = $options;
@ -104,9 +83,7 @@ if (!function_exists('formatTreeList')) {
} }
return $data; return $data;
} }
}
if (!function_exists('formatTree')) {
function formatTree(&$options, $name, $pidName = 'pid', $pid = 0, $level = 0, $data = []): array function formatTree(&$options, $name, $pidName = 'pid', $pid = 0, $level = 0, $data = []): array
{ {
$_options = $options; $_options = $options;
@ -120,9 +97,7 @@ if (!function_exists('formatTree')) {
} }
return $data; return $data;
} }
}
if (!function_exists('formatCascaderData')) {
function formatCascaderData(&$options, $name, $baseLevel = 0, $pidName = 'pid', $pid = 0, $level = 0, $data = []): array function formatCascaderData(&$options, $name, $baseLevel = 0, $pidName = 'pid', $pid = 0, $level = 0, $data = []): array
{ {
$_options = $options; $_options = $options;
@ -137,19 +112,14 @@ if (!function_exists('formatCascaderData')) {
} }
return $data; return $data;
} }
}
/**
/**
* @function toMap 数组重新组装 * @function toMap 数组重新组装
* @param array $data 数据 * @param array $data 数据
* @param string $field key * @param string $field key
* @param string $value value default null * @param string $value value default null
* @return array * @return array
* @author 张先生
* @date 2020-04-01
*/ */
if (!function_exists('toMap')) {
function toMap(array $data, $field = 'id', $value = '') function toMap(array $data, $field = 'id', $value = '')
{ {
$result = array(); $result = array();
@ -169,32 +139,23 @@ if (!function_exists('toMap')) {
return $result; return $result;
} }
}
/** /**
* @function getUniqueListByArray 从数组中获取某个字段的值,重新拼装成新的一维数组 * @function getUniqueListByArray 从数组中获取某个字段的值,重新拼装成新的一维数组
* @param array $data 数据 * @param array $data 数据
* @param string $field key * @param string $field key
* @return array * @return array
* @author 张先生
* @date 2020-04-01
*/ */
if (!function_exists('getUniqueListByArray')) {
function getUniqueListByArray(array $data, $field = 'id') function getUniqueListByArray(array $data, $field = 'id')
{ {
return array_unique(array_values(array_column($data, $field))); return array_unique(array_values(array_column($data, $field)));
} }
}
static function isPhone($test)
if (!function_exists('isPhone')) {
function isPhone($test)
{ {
return !preg_match("/^1[3456789]{1}\d{9}$/", $test); return !preg_match("/^1[3456789]{1}\d{9}$/", $test);
} }
}
if (!function_exists('getMonth')) {
/** /**
* 获取本季度 time * 获取本季度 time
* @param int|string $time * @param int|string $time
@ -211,10 +172,7 @@ if (!function_exists('getMonth')) {
$lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y'))); $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
return array($firstday, $lastday); return array($firstday, $lastday);
} }
}
if (!function_exists('getModelTime')) {
/** /**
* @param BaseQuery $model * @param BaseQuery $model
* @param string $section * @param string $section
@ -273,9 +231,7 @@ if (!function_exists('getModelTime')) {
} }
return $model; return $model;
} }
}
if (!function_exists('hasMany')) {
function hasMany($collection, $field, $model, $searchKey, $insertKey, $where = [] ,$select = '*') function hasMany($collection, $field, $model, $searchKey, $insertKey, $where = [] ,$select = '*')
{ {
$ids = []; $ids = [];
@ -314,9 +270,7 @@ if (!function_exists('hasMany')) {
return $collection; return $collection;
} }
}
if (!function_exists('activeProductSku')) {
//格式活动商品SKU //格式活动商品SKU
function activeProductSku($activeData, $type = null) function activeProductSku($activeData, $type = null)
{ {
@ -372,10 +326,7 @@ if (!function_exists('activeProductSku')) {
} }
return compact('data', 'price'); return compact('data', 'price');
} }
}
if (!function_exists('systemConfig')) {
/** /**
* 获取系统配置 * 获取系统配置
* *
@ -384,13 +335,11 @@ if (!function_exists('systemConfig')) {
* @author xaboy * @author xaboy
* @day 2020-05-08 * @day 2020-05-08
*/ */
function systemConfig($key) static function systemConfig($key)
{ {
return merchantConfig(0, $key); return self::merchantConfig(0, $key);
} }
}
if (!function_exists('getDatesBetweenTwoDays')) {
function getDatesBetweenTwoDays($startDate, $endDate) function getDatesBetweenTwoDays($startDate, $endDate)
{ {
$dates = []; $dates = [];
@ -412,9 +361,7 @@ if (!function_exists('getDatesBetweenTwoDays')) {
return $dates; return $dates;
} }
} }
}
if (!function_exists('getStartModelTime')) {
function getStartModelTime(string $section) function getStartModelTime(string $section)
{ {
switch ($section) { switch ($section) {
@ -442,9 +389,7 @@ if (!function_exists('getStartModelTime')) {
return date('Y-m-d H:i:s'); return date('Y-m-d H:i:s');
} }
} }
}
if (!function_exists('merchantConfig')) {
/** /**
* 获取商户配置 * 获取商户配置
* *
@ -454,37 +399,35 @@ if (!function_exists('merchantConfig')) {
* @author xaboy * @author xaboy
* @day 2020-05-08 * @day 2020-05-08
*/ */
function merchantConfig(int $merId, $key) static function merchantConfig(int $merId, $key)
{ {
$request = request(); $request = request();
$make = app()->make(SystemConfigValue::class); $make = app()->make(SystemConfigValue::class);
if (is_array($key)) { if (is_array($key)) {
$_key = []; $_key = [];
$cacheData = []; $cacheData = [];
foreach ($key as $v) { foreach ($key as $v) {
if ($request->hasCache($merId, $v)) { // if ($request->hasCache($merId, $v)) {
$cacheData[$v] = $request->getCache($merId, $v); // $cacheData[$v] = $request->getCache($merId, $v);
} else { // } else {
$_key[] = $v; $_key[] = $v;
} // }
} }
if (!count($_key)) return $cacheData; if (!count($_key)) return $cacheData;
$data = $make->more($_key, $merId); $data = $make->more($_key, $merId);
$request->setCache($merId, $data); // $request->setCache($merId, $data);
$data += $cacheData; $data += $cacheData;
} else { } else {
if ($request->hasCache($merId, $key)) { // if ($request->hasCache($merId, $key)) {
$data = $request->getCache($merId, $key); // $data = $request->getCache($merId, $key);
} else { // } else {
$data = $make->get($key, $merId); $data = $make->get($key, $merId);
$request->setCache($merId, $key, $data); // $request->setCache($merId, $key, $data);
} // }
} }
return $data; return $data;
} }
}
if (!function_exists('filter_emoji')) {
// 过滤掉emoji表情 // 过滤掉emoji表情
function filter_emoji($str) function filter_emoji($str)
@ -498,9 +441,6 @@ if (!function_exists('filter_emoji')) {
); );
return $str; return $str;
} }
}
if (!function_exists('setHttpType')) {
/** /**
* TODO 修改 https http 移动到common * TODO 修改 https http 移动到common
@ -518,9 +458,6 @@ if (!function_exists('setHttpType')) {
} }
return $url; return $url;
} }
}
if (!function_exists('remoteImage')) {
/** /**
* TODO 获取小程序二维码是否生成 * TODO 获取小程序二维码是否生成
@ -537,9 +474,9 @@ if (!function_exists('remoteImage')) {
if (is_array($result)) return ['status' => false, 'msg' => $result['errcode'] . '---' . $result['errmsg']]; if (is_array($result)) return ['status' => false, 'msg' => $result['errcode'] . '---' . $result['errmsg']];
return ['status' => true]; return ['status' => true];
} }
}
if (!function_exists('image_to_base64')) {
//-------------------------
/** /**
* 获取图片转为base64 * 获取图片转为base64
* @param string $avatar * @param string $avatar
@ -584,7 +521,6 @@ if (!function_exists('image_to_base64')) {
} }
if (!function_exists('put_image')) {
/** /**
* 获取图片转为base64 * 获取图片转为base64
* @param string $avatar * @param string $avatar
@ -620,9 +556,7 @@ if (!function_exists('put_image')) {
return false; return false;
} }
} }
}
if (!function_exists('path_to_url')) {
/** /**
* 路径转url路径 * 路径转url路径
* @param $path * @param $path
@ -632,9 +566,7 @@ if (!function_exists('path_to_url')) {
{ {
return trim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '.'); return trim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '.');
} }
}
if (!function_exists('tidy_url')) {
/** /**
* 路径转url路径 * 路径转url路径
* @param $url * @param $url
@ -657,10 +589,8 @@ if (!function_exists('tidy_url')) {
$url = set_http_type($url, $http); $url = set_http_type($url, $http);
return $url; return $url;
} }
}
if (!function_exists('curl_file_exist')) {
/** /**
* CURL 检测远程文件是否在 * CURL 检测远程文件是否在
* @param $url * @param $url
@ -682,10 +612,8 @@ if (!function_exists('curl_file_exist')) {
return false; return false;
} }
} }
}
if (!function_exists('set_http_type')) {
/** /**
* 修改 https http * 修改 https http
* @param $url $url 域名 * @param $url $url 域名
@ -702,10 +630,8 @@ if (!function_exists('set_http_type')) {
} }
return $url; return $url;
} }
}
if (!function_exists('getTimes')) {
function getTimes() function getTimes()
{ {
$dates = []; $dates = [];
@ -716,9 +642,7 @@ if (!function_exists('getTimes')) {
} }
return $dates; return $dates;
} }
}
if (!function_exists('monday')) {
/** /**
* 获取周一 * 获取周一
* *
@ -731,10 +655,8 @@ if (!function_exists('monday')) {
{ {
return date('Y-m-d', strtotime('Sunday -6 day', $time ?: time())); return date('Y-m-d', strtotime('Sunday -6 day', $time ?: time()));
} }
}
if (!function_exists('attr_format')) {
/** /**
* 格式化属性 * 格式化属性
* @param $arr * @param $arr
@ -781,9 +703,7 @@ if (!function_exists('attr_format')) {
} }
return [$data, $res]; return [$data, $res];
} }
}
if (!function_exists('filter_emoji')) {
//过滤掉emoji表情 //过滤掉emoji表情
function filter_emoji($str) function filter_emoji($str)
{ {
@ -792,7 +712,6 @@ if (!function_exists('filter_emoji')) {
}, $str); }, $str);
return $str; return $str;
} }
}
/** /**
* 高德经纬度改百度经纬度 * 高德经纬度改百度经纬度
@ -800,7 +719,6 @@ if (!function_exists('filter_emoji')) {
* @param $lat 纬度 * @param $lat 纬度
* @return mixed * @return mixed
*/ */
if (!function_exists('bd_encrypt')) {
function bd_encrypt($lng, $lat) function bd_encrypt($lng, $lat)
{ {
$x_pi = 3.14159265358979324 * 3000.0 / 180.0; $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
@ -813,10 +731,8 @@ if (!function_exists('bd_encrypt')) {
$data['lat'] = $z * sin($theta) + 0.006; $data['lat'] = $z * sin($theta) + 0.006;
return $data; return $data;
} }
}
if (!function_exists('aj_captcha_check_one')) {
/** /**
* 验证滑块1次验证 * 验证滑块1次验证
* @param string $token * @param string $token
@ -828,9 +744,7 @@ if (!function_exists('aj_captcha_check_one')) {
aj_get_serevice($captchaType)->check($token, $pointJson); aj_get_serevice($captchaType)->check($token, $pointJson);
return true; return true;
} }
}
if (!function_exists('aj_captcha_check_two')) {
/** /**
* 验证滑块2次验证 * 验证滑块2次验证
* @param string $token * @param string $token
@ -842,10 +756,8 @@ if (!function_exists('aj_captcha_check_two')) {
aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification); aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification);
return true; return true;
} }
}
if (!function_exists('validateIDCard')) {
function validateIDCard(string $idcard) function validateIDCard(string $idcard)
{ {
@ -893,7 +805,6 @@ if (!function_exists('validateIDCard')) {
return true; return true;
} }
} }
}
} }

View File

@ -10,6 +10,7 @@ class ShippingTemplate extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_shipping_template'; protected $table = 'eb_shipping_template';
protected $pk = 'shipping_template_id';
/** /**
* @param int $merId * @param int $merId
@ -49,14 +50,20 @@ class ShippingTemplate extends Model
$temp = self::create($data); $temp = self::create($data);
if($data['appoint']) { if($data['appoint']) {
$settlefree = $this->settleFree($free, $temp['shipping_template_id']); $settlefree = $this->settleFree($free, $temp['shipping_template_id']);
(new ShippingTemplateFree)->insertAll($settlefree);
(app()->make(ShippingTemplateFree::class))->addData($settlefree);
} }
$settleRegion = $this->settleRegion($region, $temp['shipping_template_id']); $settleRegion = $this->settleRegion($region, $temp['shipping_template_id']);
(new ShippingTemplateRegion)->insertAll($settleRegion); (app()->make(ShippingTemplateRegion::class))->addData($settleRegion);
if($data['undelivery'] == 1){ if($data['undelivery'] == 1){
$settleUndelives = $this->settleUndelives($undelives,$temp['shipping_template_id']); $settleUndelives = $this->settleUndelives($undelives,$temp['shipping_template_id']);
(new ShippingTemplateUndelive)->create($settleUndelives);
(app()->make(ShippingTemplateUndelive::class))->create($settleUndelives);
} }
}); });
} }
@ -113,6 +120,7 @@ class ShippingTemplate extends Model
public function settleUndelives($data,$id) public function settleUndelives($data,$id)
{ {
if (isset($v['city_id']) && !is_array($data['city_id'])) throw new ValidateException('指定不配送参数类型错误'); if (isset($v['city_id']) && !is_array($data['city_id'])) throw new ValidateException('指定不配送参数类型错误');
return ['temp_id' => $id, 'city_id' => $data['city_id']]; return ['temp_id' => $id, 'city_id' => $data['city_id']];
} }
} }

View File

@ -8,6 +8,7 @@ class ShippingTemplateFree extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_shipping_template_free'; protected $table = 'eb_shipping_template_free';
protected $pk = 'shipping_template_free_id';
/** /**
@ -16,7 +17,7 @@ class ShippingTemplateFree extends Model
* @param array $data * @param array $data
* @return mixed * @return mixed
*/ */
public function insertAll(array $data) public function addData(array $data)
{ {
return self::insertAll($data); return self::insertAll($data);
} }

View File

@ -12,6 +12,7 @@ class ShippingTemplateRegion extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_shipping_template_region'; protected $table = 'eb_shipping_template_region';
protected $pk = 'shipping_template_region_id';
/** /**
@ -20,9 +21,9 @@ class ShippingTemplateRegion extends Model
* @param array $data * @param array $data
* @return mixed * @return mixed
*/ */
public function insertAll(array $data) public function addData(array $data)
{ {
return self::insertAll($data); return ShippingTemplateRegion::insertAll($data);
} }
} }

View File

@ -12,4 +12,5 @@ class ShippingTemplateUndelive extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_shipping_template_undelivery'; protected $table = 'eb_shipping_template_undelivery';
protected $pk = 'shipping_template_undelivery_id';
} }

View File

@ -7,6 +7,7 @@ use think\Model;
use think\facade\Db; use think\facade\Db;
use think\exception\ValidateException; use think\exception\ValidateException;
use app\common\model\merchant\system\merchant\Merchant; use app\common\model\merchant\system\merchant\Merchant;
use app\common\model\merchant\Common;
/** /**
* @mixin \think\Model * @mixin \think\Model
@ -15,7 +16,8 @@ class ProductCopy extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_product_copy'; protected $table = 'eb_store_product_copy';
protected $pk = 'store_product_copy_id';
/** /**
@ -26,10 +28,10 @@ class ProductCopy extends Model
*/ */
public function defaulCopyNum($merId) public function defaulCopyNum($merId)
{ {
if(systemConfig('copy_product_status')){ if(Common::systemConfig('copy_product_status')){
$data = [ $data = [
'type' => 'sys', 'type' => 'sys',
'num' => systemConfig('copy_product_defaul'), 'num' => Common::systemConfig('copy_product_defaul'),
'message' => '赠送次数', 'message' => '赠送次数',
]; ];
$this->add($data,$merId); $this->add($data,$merId);
@ -88,4 +90,21 @@ class ProductCopy extends Model
} }
}); });
} }
public function search(array $where)
{
return $this->getModel()::getDB()
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
$query->where('mer_id',$where['mer_id']);
})
->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
if($where['type'] == 'copy'){
$query->where('type','in',['taobao','jd','copy']);
} else {
$query->where('type',$where['type']);
}
})
->order('create_time DESC');
}
} }

View File

@ -13,9 +13,13 @@ namespace app\common\model\merchant\system\merchant;
use think\Model; use think\Model;
use app\common\model\merchant\user\UserBill as UserBillModel; use app\common\model\merchant\user\UserBill as UserBillModel;
use app\common\model\merchant\store\ShippingTemplate; use app\common\model\merchant\store\ShippingTemplate;
use app\common\model\merchant\Common;
use app\common\model\merchant\system\merchant\MerchantAddress;
use app\common\model\merchant\store\product\ProductCopy;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Db; use think\facade\Db;
/** /**
* @mixin \think\Model * @mixin \think\Model
*/ */
@ -23,6 +27,7 @@ class Merchant extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_merchant'; protected $table = 'eb_merchant';
protected $pk = 'mer_id';
public function merchantType() public function merchantType()
{ {
@ -43,36 +48,48 @@ class Merchant extends Model
{ {
if ($this->fieldExists('mer_name', $data['mer_name'])) if ($this->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名已存在'); throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone'])) if ($data['mer_phone'] && Common::isPhone($data['mer_phone']))
throw new ValidateException('请输入正确的手机号'); throw new ValidateException('请输入正确的手机号');
$merchantCategory = app()->make(MerchantCategory::class); $merchantCategory = app()->make(MerchantCategory::class);
$admin = app()->make(MerchantAdmin::class); $admin = app()->make(MerchantAdmin::class);
if (!$data['category_id'] || !$merchantCategory->idIsExists($data['category_id'])){
if (!$data['category_id'] || !$merchantCategory->idIsExists($data['category_id']))
throw new ValidateException('商户分类不存在'); throw new ValidateException('商户分类不存在');
if ($admin->fieldExists('account', $data['mer_account'])) }
if ($admin->fieldExists('account', $data['mer_account'])) {
throw new ValidateException('账号已存在'); throw new ValidateException('账号已存在');
}
/** @var MerchantAdmin $make */ /** @var MerchantAdmin $make */
$make = app()->make(MerchantAdmin::class); $make = app()->make(MerchantAdmin::class);
$margin = app()->make(MerchantType::class)->get($data['type_id']); $margin = app()->make(MerchantType::class)->get($data['type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1; $data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0; $data['margin'] = $margin['margin'] ?? 0;
return Db::transaction(function () use ($data, $make) { return Db::transaction(function () use ($data, $make) {
// 创建商户帐号
$account = $data['mer_account']; $account = $data['mer_account'];
$password = $data['mer_password']; $password = $data['mer_password'];
unset($data['mer_account'], $data['mer_password']); unset($data['mer_account'], $data['mer_password']);
$merchant = self::create($data);
$merchant = $this->dao->create($data); // 创建商户管理员帐号
$make->createMerchantAccount($merchant, $account, $password); $make->createMerchantAccount($merchant, $account, $password);
$address_id = Db::name('merchant_address')->insertGetId(['mer_id'=>$merchant->mer_id,'street_id'=>$data['geo_street']]);
// 添加商圈地址
$mer_address = app()->make(MerchantAddress::class);
$address_id = $mer_address->insertGetId(['mer_id'=>$merchant->mer_id,'street_id'=>$data['geo_street']]);
if($data['area_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']]); $mer_address->where('id',$address_id)->update(['area_id'=>$data['area_id'],'village_id'=>$data['village_id']]);
} }
app()->make(ShippingTemplate::class)->createDefault($merchant->mer_id);
// 创建运费模板
app()->make(ShippingTemplate::class)->createDefault((int)$merchant->mer_id);
// 商品
app()->make(ProductCopy::class)->defaulCopyNum($merchant->mer_id); app()->make(ProductCopy::class)->defaulCopyNum($merchant->mer_id);
return $merchant; return $merchant;
}); });
} }
@ -115,6 +132,15 @@ class Merchant extends Model
// return []; // return [];
} }
/**
* @param int $id
* @return array|Model|null
*/
public function get($id)
{
return Merchant::getInstance()->where('is_del', 0)->find($id);
}
/** /**
* 查询指定商户信息 * 查询指定商户信息
*/ */
@ -146,4 +172,21 @@ class Merchant extends Model
$merchant->save(); $merchant->save();
} }
/**
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-03-30
*/
public function fieldExists($field, $value, ?int $except = null): bool
{
$query = self::where($field, $value);
if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
return $query->where('is_del', 0)->count() > 0;
}
} }

View File

@ -0,0 +1,15 @@
<?php
declare (strict_types = 1);
namespace app\common\model\merchant\system\merchant;
use think\Model;
/**
* @mixin \think\Model
*/
class MerchantAddress extends Model
{
protected $connection = 'shop';
protected $table = 'eb_merchant_address';
}

View File

@ -13,6 +13,7 @@ class MerchantAdmin extends Model
// //
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_merchant_admin'; protected $table = 'eb_merchant_admin';
protected $pk = 'merchant_admin_id';
const PASSWORD_TYPE_ADMIN = 1; const PASSWORD_TYPE_ADMIN = 1;
const PASSWORD_TYPE_MERCHANT = 2; const PASSWORD_TYPE_MERCHANT = 2;

View File

@ -12,7 +12,7 @@ class MerchantCategory extends Model
{ {
protected $connection = 'shop'; protected $connection = 'shop';
protected $table = 'eb_merchant_category'; protected $table = 'eb_merchant_category';
protected $pk = 'merchant_category_id';
/** /**
* @param int $id * @param int $id
@ -37,6 +37,7 @@ class MerchantCategory extends Model
{ {
$query = self::where($field, $value); $query = self::where($field, $value);
if (!is_null($except)) $query->where($this->getPk(), '<>', $except); if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
return $query->count() > 0; return $query->count() > 0;
} }
} }

View File

@ -14,6 +14,7 @@ use app\common\model\merchant\system\merchant\MerchantCategory;
use think\Model; use think\Model;
use think\facade\Db; use think\facade\Db;
use think\exception\ValidateException; use think\exception\ValidateException;
use app\common\model\merchant\Common;
/** /**
* @mixin \think\Model * @mixin \think\Model
@ -92,15 +93,6 @@ class MerchantIntention extends Model
return $query; return $query;
} }
/**
* 修改审核状态
*/
public function getStatusAttr($value)
{
$status = [0=>'待审核', 1=>'审核已通过',2=>'审核未通过'];
return $status[$value];
}
public function Edit($id, $data) public function Edit($id, $data)
@ -137,12 +129,13 @@ class MerchantIntention extends Model
if (!$intention) if (!$intention)
throw new ValidateException('信息不存在'); throw new ValidateException('信息不存在');
if ($intention->status) if ($intention->status)
throw new ValidateException('状态有误,修改失败'); throw new ValidateException('申请状态有误,修改失败');
//TODO: 此处需开发为可配置字段 //TODO: 此处Common类systemConfig方法内缓存方法有bug请及时修复
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']); $config = app()->make(Common::class)->systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$margin = app()->make(MerchantType::class)->get($intention['mer_type_id']); $margin = app()->make(MerchantType::class)->get($intention['mer_type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1; $data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0; $data['margin'] = $margin['margin'] ?? 0;
$merData = []; $merData = [];
@ -174,7 +167,7 @@ class MerchantIntention extends Model
'mer' => $intention['mer_name'], 'mer' => $intention['mer_name'],
'phone' => $intention['phone'], 'phone' => $intention['phone'],
'pwd' => $password ?? '', 'pwd' => $password ?? '',
// 'site_name' => systemConfig('site_name'), 'site_name' => Common::systemConfig('site_name'),
]; ];
} }
} }
@ -183,72 +176,26 @@ class MerchantIntention extends Model
'phone' => $intention['phone'], 'phone' => $intention['phone'],
'date' => date('m月d日', strtotime($intention->create_time)), 'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'], 'mer' => $intention['mer_name'],
// 'site' => systemConfig('site_name'), 'site' => Common::systemConfig('site_name'),
]; ];
} }
self::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) { Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) {
if ($data['status'] == 1) { if ($data['status'] == 1) {
if ($create) { if ($create) {
// 创建帐号
$merchant = app()->make(Merchant::class)->createMerchant($merData); $merchant = app()->make(Merchant::class)->createMerchant($merData);
$data['mer_id'] = $merchant->mer_id; $data['mer_id'] = $merchant->mer_id;
// 暂不开通通知 // 暂不开通通知
// Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]); // Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
} }
} else { } else {
// 失败
echo '失败';
// Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]); // Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
} }
$intention->save($data); $intention->save($data);
}); });
} }
protected function isPhone($test)
{
return !preg_match("/^1[3456789]{1}\d{9}$/", $test);
}
/**
* @param array $data
* @author xaboy
* @day 2020-04-17
*/
protected function createMerchant(array $data)
{
if ($this->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && self::isPhone($data['mer_phone']))
throw new ValidateException('请输入正确的手机号');
$merchantCategory = new MerchantCategory;
$merchantAdmin = new MerchantAdmin;
if (!$data['category_id'] || !$merchantCategory->exists($data['category_id']))
throw new ValidateException('商户分类不存在');
if ($merchantAdmin->fieldExists('account', $data['mer_account']))
throw new ValidateException('账号已存在');
/** @var MerchantAdmin $make */
$make = new MerchantCategory;
$margin = (new MerchantType)->get($data['type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0;
return Db::transaction(function () use ($data, $make) {
$account = $data['mer_account'];
$password = $data['mer_password'];
unset($data['mer_account'], $data['mer_password']);
$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']]);
}
app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id);
app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id);
return $merchant;
});
}
} }

View File

@ -22,6 +22,20 @@ class MerchantType extends Model
protected $table = 'eb_merchant_type'; protected $table = 'eb_merchant_type';
/**
* @param int $id
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-03-27
*/
public function get($id)
{
return self::find($id);
}
/** /**
* 查询店铺类型数据 * 查询店铺类型数据
* *