添加:供应链 - 供应商添加、供应商列表查看接口
修复:酒道馆使用积分显示错误,应该显示兑换用户的积分,实际显示了操作员的积分 修复:订单核销后未成功解冻酒卡额度 修复:短信验证码可能发送失败的问题
This commit is contained in:
parent
9408dd2208
commit
5b0d7b0ca2
|
|
@ -1056,11 +1056,10 @@ if (!function_exists('aj_captcha_check_two')) {
|
||||||
* @param string $pointJson
|
* @param string $pointJson
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function aj_captcha_check_two(string $captchaType, string $captchaVerification,string $token)
|
function aj_captcha_check_two(string $captchaType, string $captchaVerification,string $token = ''){
|
||||||
{
|
if($token) aj_get_serevice($captchaType)->verificationByEncryptCodeV2($captchaVerification,$token);
|
||||||
// aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification);
|
else aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification);
|
||||||
|
|
||||||
aj_get_serevice($captchaType)->verificationByEncryptCodeV2($captchaVerification,$token);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
namespace app\controller\admin\system\supplier;
|
||||||
|
|
||||||
|
|
||||||
|
use app\services\supplier\SystemSupplierServices;
|
||||||
|
use crmeb\basic\BaseController;
|
||||||
|
use think\App;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
|
||||||
|
class Supplier extends BaseController{
|
||||||
|
|
||||||
|
public function __construct(App $app, SystemSupplierServices $services){
|
||||||
|
parent::__construct($app);
|
||||||
|
$this->services = $services;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 账号添加
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 11:43
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function accountCreate(){
|
||||||
|
// 参数获取
|
||||||
|
$data = $this->checkParam();
|
||||||
|
// 添加账号
|
||||||
|
$this->services->create((array)$data);
|
||||||
|
|
||||||
|
return app('json')->success('添加成功');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 添加|编辑 账号参数获取
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 10:56
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function checkParam():array{
|
||||||
|
// 接收表单参数
|
||||||
|
$supplierId = (int)$this->request->param('supplier_id');
|
||||||
|
$accountInfo = $this->request->params([
|
||||||
|
'supplier_name',
|
||||||
|
'detailed_address',
|
||||||
|
'name',
|
||||||
|
['phone',''],
|
||||||
|
'email',
|
||||||
|
'sort',
|
||||||
|
'is_show',
|
||||||
|
'is_examine',
|
||||||
|
'mark',
|
||||||
|
]);
|
||||||
|
$accountPassword = $this->request->params([
|
||||||
|
'supplier_account',
|
||||||
|
'supplier_password',
|
||||||
|
]);
|
||||||
|
// 数据判断
|
||||||
|
$nameIsHave = $this->services->isHave('supplier_name',$accountInfo['supplier_name'],$supplierId);
|
||||||
|
if($nameIsHave) throw new ValidateException('供应商名称已经存在,请勿重复添加!');
|
||||||
|
if (!empty($accountInfo['phone']) && isPhone($accountInfo['phone'])) throw new ValidateException('请输入正确的手机号!');
|
||||||
|
$accountIsHas = $this->services->accountIsHas($accountPassword['supplier_account'],$supplierId);
|
||||||
|
if($accountIsHas) throw new ValidateException('账号已存在,请勿重复添加!');
|
||||||
|
|
||||||
|
return compact('supplierId','accountInfo','accountPassword');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 14:29
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getList(){
|
||||||
|
$search = $this->request->params(['supplier_name','name','phone','is_show']);
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
|
||||||
|
$field = 'id,supplier_name,avatar,name,phone,is_show,add_time';
|
||||||
|
$data = $this->services->supplierList($search, $page, $limit, $field);
|
||||||
|
|
||||||
|
return app('json')->success($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,6 @@ class Exchange extends BaseController{
|
||||||
public function getUserHold(){
|
public function getUserHold(){
|
||||||
$params = $this->request->params(['consume_uid']);
|
$params = $this->request->params(['consume_uid']);
|
||||||
$uid = $this->request->uid();
|
$uid = $this->request->uid();
|
||||||
$user = $this->request->userInfo();
|
|
||||||
// 判断:是否存在指定消费者,不存在则使用当前登录用户
|
// 判断:是否存在指定消费者,不存在则使用当前登录用户
|
||||||
$uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid;
|
$uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid;
|
||||||
// 获取额度
|
// 获取额度
|
||||||
|
|
@ -45,6 +44,7 @@ class Exchange extends BaseController{
|
||||||
])
|
])
|
||||||
->where('uid',$uid)
|
->where('uid',$uid)
|
||||||
->findOrEmpty();
|
->findOrEmpty();
|
||||||
|
$user = app()->make(UserRepository::class)->getSearch([])->where('uid',$uid)->findOrEmpty();
|
||||||
$info->available = (float)$info->available;
|
$info->available = (float)$info->available;
|
||||||
$info->available_integral = (float)$user->exchange_integral;
|
$info->available_integral = (float)$user->exchange_integral;
|
||||||
$info->diff_rate = 30;// 差价 应补金额,默认为30%
|
$info->diff_rate = 30;// 差价 应补金额,默认为30%
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ abstract class BaseDao
|
||||||
* 获取模型
|
* 获取模型
|
||||||
* @return BaseModel
|
* @return BaseModel
|
||||||
*/
|
*/
|
||||||
protected function getModel()
|
public function getModel()
|
||||||
{
|
{
|
||||||
return app()->make($this->setModel());
|
return app()->make($this->setModel());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,4 +50,26 @@ class SystemSupplierDao extends BaseDao
|
||||||
$query->order($order);
|
$query->order($order);
|
||||||
})->field($field)->select()->toArray();
|
})->field($field)->select()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 公共搜索模型
|
||||||
|
public function searchModel(array $search){
|
||||||
|
$query = $this->getModel()
|
||||||
|
->when(isset($search['supplier_name']) && $search['supplier_name'] !== '', function ($query) use ($search) {
|
||||||
|
$query->where('supplier_name','like', "%{$search['supplier_name']}%");
|
||||||
|
})
|
||||||
|
->when(isset($search['name']) && $search['name'] !== '', function ($query) use ($search) {
|
||||||
|
$query->where('name','like', "%{$search['name']}%");
|
||||||
|
})
|
||||||
|
->when(isset($search['phone']) && $search['phone'] !== '', function ($query) use ($search) {
|
||||||
|
$query->where('phone', $search['phone']);
|
||||||
|
})
|
||||||
|
->when(isset($search['is_show']) && $search['is_show'] !== '', function ($query) use ($search) {
|
||||||
|
$query->where('is_show', $search['is_show']);
|
||||||
|
})
|
||||||
|
->where('is_del',0);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,22 @@ return [
|
||||||
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
||||||
// 订单支付成功事件触发
|
// 订单支付成功事件触发
|
||||||
'order.paySuccess' => [
|
'order.paySuccess' => [
|
||||||
// 赠送兑换额度
|
// 赠送酒卡额度
|
||||||
'app\listener\exchangeQuota\OrderPaySuccessEvent'
|
'app\listener\exchangeQuota\OrderPaySuccessEvent'
|
||||||
],
|
],
|
||||||
// 订单完成事件触发(进入待评价)
|
// 订单完成事件触发(进入待评价)
|
||||||
'order.take' => [
|
'order.take' => [
|
||||||
// 兑换额度解冻
|
// 酒卡额度解冻
|
||||||
'app\listener\exchangeQuota\OrderTakeEvent'
|
'app\listener\exchangeQuota\OrderTakeEvent'
|
||||||
],
|
],
|
||||||
|
// 订单核销成功事件触发
|
||||||
|
'order.verify' => [
|
||||||
|
// 酒卡额度解冻
|
||||||
|
'app\listener\exchangeQuota\OrderVerifyEvent'
|
||||||
|
],
|
||||||
// 订单退款事件
|
// 订单退款事件
|
||||||
'refund.agree' => [
|
'refund.agree' => [
|
||||||
// 兑换额度相关处理
|
// 酒卡额度相关处理
|
||||||
'app\listener\exchangeQuota\OrderAgreeRefundEvent'
|
'app\listener\exchangeQuota\OrderAgreeRefundEvent'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\listener\exchangeQuota;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\store\order\StoreOrder;
|
||||||
|
use app\common\model\user\ExchangeQuota;
|
||||||
|
use app\common\model\user\ExchangeQuotaRecord;
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
|
||||||
|
class OrderVerifyEvent{
|
||||||
|
public $groupOrder;
|
||||||
|
|
||||||
|
public function handle($data){
|
||||||
|
try{
|
||||||
|
$order = $data['order'];
|
||||||
|
// Log::info('订单核销 - 酒卡额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1));
|
||||||
|
// 判断:如果存在上级id 则使用上级id
|
||||||
|
$orderId = $order->main_id > 0 ? $order->main_id : $order->order_id;
|
||||||
|
# 获取变更记录 条件:order_id=当前订单id、变更类型=增加
|
||||||
|
$sum = (float)ExchangeQuotaRecord::where('order_id',$orderId)
|
||||||
|
->where('change_type',1)
|
||||||
|
->where('source',0) // 仅查询购买赠送 进行解冻
|
||||||
|
->sum('change_quantity');
|
||||||
|
$refundSum = (float)ExchangeQuotaRecord::where('order_id',$orderId)
|
||||||
|
->where('change_type',0)
|
||||||
|
->where('source',1) // 仅查询订单退款 减少内容
|
||||||
|
->sum('change_quantity');
|
||||||
|
// 剩余数量 解冻
|
||||||
|
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
|
||||||
|
if($surplusQuota > 0){
|
||||||
|
// 核销订单 会进行拆分操作 需要获取当前订单占总订单数量的比例
|
||||||
|
$totalNum = (int)$this->getRate($orderId);
|
||||||
|
$currentTotalNum = (int)$order->total_num;
|
||||||
|
$rate = (float)sprintf("%.2f",$currentTotalNum / $totalNum * 100);
|
||||||
|
$surplusQuota = (float)sprintf("%.2f",$surplusQuota * $rate / 100);
|
||||||
|
// 解冻操作
|
||||||
|
$hold = ExchangeQuota::where('uid',$order->uid)->findOrEmpty();
|
||||||
|
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
|
||||||
|
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
|
||||||
|
$hold->save();
|
||||||
|
}
|
||||||
|
}catch(\Exception $e){
|
||||||
|
Log::info('订单核销 - 酒卡额度相关处理 - 错误: '.$e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取订单总数量
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 16:03
|
||||||
|
* @param $orderId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getRate($orderId){
|
||||||
|
return app()->make(StoreOrderRepository::class)
|
||||||
|
->getSearch([])
|
||||||
|
->where(function($query) use ($orderId){
|
||||||
|
$query->where('order_id',$orderId)->whereOr('main_id',$orderId);
|
||||||
|
})->sum('total_num');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -27,298 +27,339 @@ use think\exception\ValidateException;
|
||||||
* @package app\services\supplier
|
* @package app\services\supplier
|
||||||
* @mixin SystemSupplierDao
|
* @mixin SystemSupplierDao
|
||||||
*/
|
*/
|
||||||
class SystemSupplierServices extends BaseServices
|
class SystemSupplierServices extends BaseServices{
|
||||||
{
|
protected $adminDao = NULL;
|
||||||
|
|
||||||
protected $adminDao = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造方法
|
* 构造方法
|
||||||
* SystemSupplierServices constructor.
|
* SystemSupplierServices constructor.
|
||||||
* @param SystemSupplierDao $dao
|
* @param SystemSupplierDao $dao
|
||||||
* @param SystemAdminDao $adminDao
|
* @param SystemAdminDao $adminDao
|
||||||
*/
|
*/
|
||||||
public function __construct(SystemSupplierDao $dao, SystemAdminDao $adminDao)
|
public function __construct(SystemSupplierDao $dao,SystemAdminDao $adminDao){
|
||||||
{
|
$this->dao = $dao;
|
||||||
$this->dao = $dao;
|
|
||||||
$this->adminDao = $adminDao;
|
$this->adminDao = $adminDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取供应商
|
* 获取供应商
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getSupplierInfo(int $id, string $field = '*', array $with = [])
|
public function getSupplierInfo(int $id,string $field = '*',array $with = []){
|
||||||
{
|
$info = $this->dao->getOne(['id' => $id,'is_del' => 0],$field,$with);
|
||||||
$info = $this->dao->getOne(['id' => $id, 'is_del' => 0], $field, $with);
|
if(!$info){
|
||||||
if (!$info) {
|
|
||||||
throw new ValidateException('供应商不存在');
|
throw new ValidateException('供应商不存在');
|
||||||
}
|
}
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
/**
|
* 供应商列表
|
||||||
* 供应商列表
|
* @param array $where
|
||||||
* @param array $where
|
* @param array $field
|
||||||
* @param array $field
|
* @return array
|
||||||
* @return array
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
*/
|
||||||
*/
|
public function getSupplierList(array $where,array $field = ['*']){
|
||||||
public function getSupplierList(array $where, array $field = ['*'])
|
[$page,$limit] = $this->getPageValue();
|
||||||
{
|
$list = $this->dao->getSupplierList($where,$field,$page,$limit);
|
||||||
[$page, $limit] = $this->getPageValue();
|
if($list){
|
||||||
$list = $this->dao->getSupplierList($where, $field, $page, $limit);
|
$prefix = config('admin.supplier_prefix');
|
||||||
if ($list) {
|
foreach($list as &$item){
|
||||||
$prefix = config('admin.supplier_prefix');
|
if(isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s',$item['add_time']);
|
||||||
foreach ($list as &$item) {
|
$item['prefix'] = $prefix;
|
||||||
if (isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
}
|
||||||
$item['prefix'] = $prefix;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
$count = $this->dao->count($where);
|
$count = $this->dao->count($where);
|
||||||
return compact('list', 'count');
|
return compact('list','count');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存供应商
|
|
||||||
* @param array $data
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function create(array $data)
|
|
||||||
{
|
|
||||||
if ($this->adminDao->count(['account' => $data['account'], 'admin_type' => 4, 'is_del' => 0])) {
|
|
||||||
throw new AdminException('管理员账号已存在');
|
|
||||||
}
|
|
||||||
return $this->transaction(function () use ($data) {
|
|
||||||
$adminData = [
|
|
||||||
'pwd' => $this->passwordHash($data['pwd']),
|
|
||||||
'admin_type' => 4,
|
|
||||||
'account' => $data['account'],
|
|
||||||
'roles' => '',
|
|
||||||
'real_name' => $data['name'],
|
|
||||||
'phone' => $data['phone'],
|
|
||||||
'add_time' => time(),
|
|
||||||
'level' => 0
|
|
||||||
];
|
|
||||||
unset($data['pwd'], $data['conf_pwd'], $data['account']);
|
|
||||||
|
|
||||||
// 创建管理员
|
|
||||||
$res = $this->adminDao->save($adminData);
|
|
||||||
if (!$res) throw new AdminException('管理员添加失败');
|
|
||||||
$data['admin_id'] = (int)$res->id;
|
|
||||||
$data['add_time'] = time();
|
|
||||||
|
|
||||||
// 创建供应商
|
|
||||||
$relation_id = $this->dao->save($data)->id;
|
|
||||||
if (!$relation_id) throw new AdminException('供应商添加失败');
|
|
||||||
|
|
||||||
$this->adminDao->update($res->id, ['relation_id' => $relation_id]);
|
|
||||||
return $relation_id;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改管理员
|
* 修改管理员
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function save(int $id, array $data)
|
public function save(int $id,array $data){
|
||||||
{
|
if(!$supplierInfo = $this->dao->get($id)){
|
||||||
if (!$supplierInfo = $this->dao->get($id)) {
|
throw new AdminException('供应商不存在,无法修改');
|
||||||
throw new AdminException('供应商不存在,无法修改');
|
}
|
||||||
}
|
if($supplierInfo->is_del){
|
||||||
if ($supplierInfo->is_del) {
|
throw new AdminException('供应商已经删除');
|
||||||
throw new AdminException('供应商已经删除');
|
}
|
||||||
}
|
if(!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])){
|
||||||
if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
|
throw new AdminException('管理员不存在,无法修改');
|
||||||
throw new AdminException('管理员不存在,无法修改');
|
}
|
||||||
}
|
if($adminInfo->is_del){
|
||||||
if ($adminInfo->is_del) {
|
throw new AdminException('管理员已经删除');
|
||||||
throw new AdminException('管理员已经删除');
|
}
|
||||||
}
|
//修改账号
|
||||||
//修改账号
|
if(isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'],$supplierInfo['admin_id'],4)){
|
||||||
if (isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'], $supplierInfo['admin_id'], 4)) {
|
throw new AdminException('管理员账号已存在');
|
||||||
throw new AdminException('管理员账号已存在');
|
}
|
||||||
}
|
return $this->transaction(function() use ($id,$data,$adminInfo,$supplierInfo){
|
||||||
return $this->transaction(function () use ($id, $data, $adminInfo, $supplierInfo) {
|
|
||||||
|
|
||||||
$adminData = [
|
$adminData = [
|
||||||
'pwd' => $this->passwordHash($data['pwd']),
|
'pwd' => $this->passwordHash($data['pwd']),
|
||||||
'real_name' => $data['name'] ?? $adminInfo->real_name,
|
'real_name' => $data['name'] ?? $adminInfo->real_name,
|
||||||
'phone' => $data['phone'] ?? $adminInfo->phone,
|
'phone' => $data['phone'] ?? $adminInfo->phone,
|
||||||
'account' => $data['account'] ?? $adminInfo->account
|
'account' => $data['account'] ?? $adminInfo->account
|
||||||
];
|
];
|
||||||
// 修改管理员
|
// 修改管理员
|
||||||
$res = $this->adminDao->update($adminInfo['id'], $adminData);
|
$res = $this->adminDao->update($adminInfo['id'],$adminData);
|
||||||
if (!$res) throw new AdminException('管理员修改失败');
|
if(!$res) throw new AdminException('管理员修改失败');
|
||||||
|
// 修改供应商
|
||||||
// 修改供应商
|
unset($data['pwd'],$data['conf_pwd'],$data['account']);
|
||||||
unset($data['pwd'], $data['conf_pwd'], $data['account']);
|
$this->dao->update($id,$data);
|
||||||
$this->dao->update($id, $data);
|
|
||||||
$res1 = $supplierInfo->save();
|
$res1 = $supplierInfo->save();
|
||||||
if (!$res1) throw new AdminException('供应商修改失败');
|
if(!$res1) throw new AdminException('供应商修改失败');
|
||||||
return true;
|
return TRUE;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
/**
|
* @param int $id
|
||||||
* @param int $id
|
* @return mixed
|
||||||
* @return mixed
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
*/
|
||||||
*/
|
public function delete(int $id){
|
||||||
public function delete(int $id)
|
if(!$supplierInfo = $this->dao->get($id)){
|
||||||
{
|
throw new AdminException('供应商不存在,无法修改');
|
||||||
if (!$supplierInfo = $this->dao->get($id)) {
|
}
|
||||||
throw new AdminException('供应商不存在,无法修改');
|
if($supplierInfo->is_del){
|
||||||
}
|
throw new AdminException('供应商已经删除');
|
||||||
if ($supplierInfo->is_del) {
|
}
|
||||||
throw new AdminException('供应商已经删除');
|
if(!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])){
|
||||||
}
|
throw new AdminException('管理员不存在,无法删除');
|
||||||
if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
|
}
|
||||||
throw new AdminException('管理员不存在,无法删除');
|
if($adminInfo->is_del){
|
||||||
}
|
throw new AdminException('管理员已经删除');
|
||||||
if ($adminInfo->is_del) {
|
}
|
||||||
throw new AdminException('管理员已经删除');
|
/** @var StoreOrderServices $storeOrderServices */
|
||||||
}
|
$storeOrderServices = app()->make(StoreOrderServices::class);
|
||||||
/** @var StoreOrderServices $storeOrderServices */
|
$orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 0]);
|
||||||
$storeOrderServices = app()->make(StoreOrderServices::class);
|
if(!$orderCount){
|
||||||
$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 0]);
|
$orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 1]);
|
||||||
if (!$orderCount) {
|
if(!$orderCount){
|
||||||
$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 1]);
|
$orderCount = $storeOrderServices->count(['supplier_id' => $id,'status' => 5]);
|
||||||
if (!$orderCount) {
|
}
|
||||||
$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 5]);
|
}
|
||||||
}
|
if($orderCount){
|
||||||
}
|
return $this->fail('删除失败,该供应商还有待处理订单');
|
||||||
if ($orderCount) {
|
}
|
||||||
return $this->fail('删除失败,该供应商还有待处理订单');
|
return $this->transaction(function() use ($id,$supplierInfo,$adminInfo){
|
||||||
}
|
|
||||||
return $this->transaction(function () use ($id, $supplierInfo, $adminInfo) {
|
|
||||||
$adminInfo->status = 0;
|
$adminInfo->status = 0;
|
||||||
$adminInfo->is_del = 1;
|
$adminInfo->is_del = 1;
|
||||||
// 修改管理员
|
// 修改管理员
|
||||||
$res = $adminInfo->save();
|
$res = $adminInfo->save();
|
||||||
if (!$res) throw new AdminException('管理员删除失败');
|
if(!$res) throw new AdminException('管理员删除失败');
|
||||||
|
|
||||||
$supplierInfo->is_show = 0;
|
$supplierInfo->is_show = 0;
|
||||||
$supplierInfo->is_del = 1;
|
$supplierInfo->is_del = 1;
|
||||||
// 修改供应商
|
// 修改供应商
|
||||||
$res1 = $supplierInfo->save();
|
$res1 = $supplierInfo->save();
|
||||||
if (!$res1) throw new AdminException('供应商删除失败');
|
if(!$res1) throw new AdminException('供应商删除失败');
|
||||||
|
/** @var StoreBranchProductServices $storeBranchProducesServices */
|
||||||
/** @var StoreBranchProductServices $storeBranchProducesServices */
|
$storeBranchProducesServices = app()->make(StoreBranchProductServices::class);
|
||||||
$storeBranchProducesServices = app()->make(StoreBranchProductServices::class);
|
//删除供应商商品
|
||||||
//删除供应商商品
|
$storeBranchProducesServices->deleteProducts([],2,$id);
|
||||||
$storeBranchProducesServices->deleteProducts([], 2, $id);
|
/** @var SystemAttachmentServices $attach */
|
||||||
/** @var SystemAttachmentServices $attach */
|
$attach = app()->make(SystemAttachmentServices::class);
|
||||||
$attach = app()->make(SystemAttachmentServices::class);
|
//删除附件
|
||||||
//删除附件
|
$attach->delAttachment([],4,$id);
|
||||||
$attach->delAttachment([], 4, $id);
|
return TRUE;
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台供应商运营统计
|
* 平台供应商运营统计
|
||||||
* @param int $supplierId
|
* @param int $supplierId
|
||||||
* @param array $time
|
* @param array $time
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function supplierChart(int $supplierId, array $time)
|
public function supplierChart(int $supplierId,array $time){
|
||||||
{
|
$list = $this->dao->getSupplierList(['is_del' => 0,'is_show' => 1],['id','supplier_name']);
|
||||||
$list = $this->dao->getSupplierList(['is_del' => 0, 'is_show' => 1], ['id', 'supplier_name']);
|
|
||||||
/** @var StoreOrderServices $orderServices */
|
/** @var StoreOrderServices $orderServices */
|
||||||
$orderServices = app()->make(StoreOrderServices::class);
|
$orderServices = app()->make(StoreOrderServices::class);
|
||||||
/** @var StoreOrderRefundServices $orderRefundServices */
|
/** @var StoreOrderRefundServices $orderRefundServices */
|
||||||
$orderRefundServices = app()->make(StoreOrderRefundServices::class);
|
$orderRefundServices = app()->make(StoreOrderRefundServices::class);
|
||||||
$where = ['time' => $time];
|
$where = ['time' => $time];
|
||||||
|
$order_where = ['paid' => 1,'pid' => 0,'is_del' => 0,'is_system_del' => 0,'refund_status' => [0,3]];
|
||||||
$order_where = ['paid' => 1, 'pid' => 0, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3]];
|
|
||||||
$refund_where = ['refund_type' => 6];
|
$refund_where = ['refund_type' => 6];
|
||||||
foreach ($list as &$item) {
|
foreach($list as &$item){
|
||||||
$supplier_where = ['supplier_id' => $item['id']];
|
$supplier_where = ['supplier_id' => $item['id']];
|
||||||
$item['order_price'] = $orderServices->sum($where + $supplier_where + $order_where, 'pay_price', true);
|
$item['order_price'] = $orderServices->sum($where + $supplier_where + $order_where,'pay_price',TRUE);
|
||||||
$item['order_count'] = $orderServices->count($where + $supplier_where + $order_where);
|
$item['order_count'] = $orderServices->count($where + $supplier_where + $order_where);
|
||||||
$item['refund_order_price'] = $orderRefundServices->sum($where + $supplier_where + $refund_where, 'refunded_price', true);
|
$item['refund_order_price'] = $orderRefundServices->sum($where + $supplier_where + $refund_where,'refunded_price',TRUE);
|
||||||
$item['refund_order_count'] = $orderRefundServices->count($where + $supplier_where + $refund_where);
|
$item['refund_order_count'] = $orderRefundServices->count($where + $supplier_where + $refund_where);
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 供应商选择列表
|
||||||
|
* @param array $where
|
||||||
|
* @param array $field
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getSupplierSearch(array $where,array $field = ['*']){
|
||||||
|
return $this->dao->getSupplierList($where,$field,0,0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 供应商入住审核通过创建数据
|
||||||
|
* @param int $applyId
|
||||||
|
* @param array $info
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function verifyAgreeCreate(int $applyId,array $info = []){
|
||||||
|
if(!$applyId){
|
||||||
|
throw new ValidateException('缺少申请ID');
|
||||||
|
}
|
||||||
|
/** @var SystemUserApplyServices $applyServices */
|
||||||
|
$applyServices = app()->make(SystemUserApplyServices::class);
|
||||||
|
if(!$info){
|
||||||
|
$info = $applyServices->get($applyId);
|
||||||
|
if(!$info){
|
||||||
|
throw new ValidateException('申请数据不存在');
|
||||||
|
}
|
||||||
|
$info = $info->toArray();
|
||||||
|
}
|
||||||
|
$data = [
|
||||||
|
'supplier_name' => $info['system_name'],
|
||||||
|
'account' => $this->getAccount($info['phone']),
|
||||||
|
'phone' => $info['phone'],
|
||||||
|
'name' => $info['name'],
|
||||||
|
'pwd' => substr($info['phone'],-6)
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
// todo 版本迭代 当前功能暂不可用
|
||||||
* 供应商选择列表
|
throw new ValidateException('开发中...');
|
||||||
* @param array $where
|
// $supplier_id = $this->create($data);
|
||||||
* @param array $field
|
// return $this->dao->get($supplier_id)->toArray();
|
||||||
* @return array
|
}
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
/**
|
||||||
* @throws \think\db\exception\DbException
|
* 获取同意申请 创建账号
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @param string $phone
|
||||||
*/
|
* @return string
|
||||||
public function getSupplierSearch(array $where, array $field = ['*'])
|
*/
|
||||||
{
|
public function getAccount(string $phone){
|
||||||
return $this->dao->getSupplierList($where, $field, 0, 0);
|
$account = '';
|
||||||
|
if($phone){
|
||||||
|
//当前手机号当作账号是否存在
|
||||||
|
$adminDCount = $this->adminDao->count(['account' => $phone,'admin_type' => 4,'is_del' => 0]);
|
||||||
|
$account = $phone;
|
||||||
|
if($adminDCount){
|
||||||
|
$account = $account.'_'.$adminDCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 添加供应商
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 11:43
|
||||||
|
* @param array $data
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function create(array $data){
|
||||||
|
return $this->transaction(function() use ($data){
|
||||||
|
// 添加供应商信息
|
||||||
|
$relation_id = $this->dao->save($data['accountInfo'])->id;
|
||||||
|
if(!$relation_id) throw new AdminException('供应商添加失败');
|
||||||
|
// 添加账号信息
|
||||||
|
$accountPassword = $data['accountPassword'];
|
||||||
|
$adminId = (int)$this->adminDao->getModel()->insertGetId([
|
||||||
|
'pwd' => $this->passwordHash($accountPassword['supplier_password']),
|
||||||
|
'admin_type' => 4,
|
||||||
|
'account' => $accountPassword['supplier_account'],
|
||||||
|
'roles' => 1,
|
||||||
|
'real_name' => $data['accountInfo']['supplier_name'],
|
||||||
|
'phone' => $data['accountInfo']['phone'],
|
||||||
|
'level' => 0,
|
||||||
|
'relation_id' => $relation_id
|
||||||
|
]);
|
||||||
|
if($adminId <= 0) throw new AdminException('管理员添加失败');
|
||||||
|
// 修改超级管理员关联
|
||||||
|
$this->dao->update($relation_id,['admin_id' => (int)$adminId]);
|
||||||
|
|
||||||
|
return $relation_id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 某个数据是否已经存在
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 10:28
|
||||||
|
* @param $field
|
||||||
|
* @param $fieldValue
|
||||||
|
* @param int $supplierId
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isHave($field,$fieldValue,int $supplierId = 0):bool{
|
||||||
|
$count = $this->dao->getModel()
|
||||||
|
->where($field,$fieldValue)
|
||||||
|
->when($supplierId > 0,function($query) use ($supplierId){
|
||||||
|
$query->where('id','<>',$supplierId);
|
||||||
|
})
|
||||||
|
->count();
|
||||||
|
return $count > 0;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 账号是否存在
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 10:53
|
||||||
|
* @param $account
|
||||||
|
* @param int $supplierId
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function accountIsHas($account,int $supplierId = 0):bool{
|
||||||
|
$count = $this->adminDao->getModel()
|
||||||
|
->where('account',$account)
|
||||||
|
->where('admin_type',4)
|
||||||
|
->where('is_del',0)
|
||||||
|
->when($supplierId > 0,function($query) use ($supplierId){
|
||||||
|
$query->where('relation_id','<>',$supplierId);
|
||||||
|
})
|
||||||
|
->count();
|
||||||
|
return $count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 获取列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/17 14:28
|
||||||
|
* @param $search
|
||||||
|
* @param $page
|
||||||
|
* @param $limit
|
||||||
|
* @param string $field
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function supplierList($search, $page, $limit, $field = '*'){
|
||||||
|
$query = $this->dao->searchModel($search);
|
||||||
|
$list = $query
|
||||||
|
->field($field)
|
||||||
|
->order('add_time desc,id desc')
|
||||||
|
->page($page, $limit)
|
||||||
|
->select();
|
||||||
|
$count = $query->count();
|
||||||
|
|
||||||
|
return compact('count', 'list');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 供应商入住审核通过创建数据
|
|
||||||
* @param int $applyId
|
|
||||||
* @param array $info
|
|
||||||
* @return array
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function verifyAgreeCreate(int $applyId, array $info = [])
|
|
||||||
{
|
|
||||||
if (!$applyId) {
|
|
||||||
throw new ValidateException('缺少申请ID');
|
|
||||||
}
|
|
||||||
/** @var SystemUserApplyServices $applyServices */
|
|
||||||
$applyServices = app()->make(SystemUserApplyServices::class);
|
|
||||||
if (!$info) {
|
|
||||||
$info = $applyServices->get($applyId);
|
|
||||||
if (!$info) {
|
|
||||||
throw new ValidateException('申请数据不存在');
|
|
||||||
}
|
|
||||||
$info = $info->toArray();
|
|
||||||
}
|
|
||||||
$data = [
|
|
||||||
'supplier_name' => $info['system_name'],
|
|
||||||
'account' => $this->getAccount($info['phone']),
|
|
||||||
'phone' => $info['phone'],
|
|
||||||
'name' => $info['name'],
|
|
||||||
'pwd' => substr($info['phone'], -6)
|
|
||||||
];
|
|
||||||
$supplier_id = $this->create($data);
|
|
||||||
return $this->dao->get($supplier_id)->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取同意申请 创建账号
|
|
||||||
* @param string $phone
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAccount(string $phone)
|
|
||||||
{
|
|
||||||
$account = '';
|
|
||||||
if ($phone) {
|
|
||||||
//当前手机号当作账号是否存在
|
|
||||||
$adminDCount = $this->adminDao->count(['account' => $phone, 'admin_type' => 4, 'is_del' => 0]);
|
|
||||||
$account = $phone;
|
|
||||||
if ($adminDCount) {
|
|
||||||
$account = $account . '_' . $adminDCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use think\facade\Route;
|
||||||
|
use app\common\middleware\AdminAuthMiddleware;
|
||||||
|
use app\common\middleware\AdminTokenMiddleware;
|
||||||
|
use app\common\middleware\AllowOriginMiddleware;
|
||||||
|
use app\common\middleware\LogMiddleware;
|
||||||
|
|
||||||
|
Route::group(function () {
|
||||||
|
Route::group('system/supplier', function () {
|
||||||
|
// 账号管理
|
||||||
|
Route::post('accountCreate', '/accountCreate')->name('systemSupplierAccountCreate')->option([
|
||||||
|
'_alias' => '账号添加',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 供应商信息
|
||||||
|
Route::get('list', '/getList')->name('systemSupplierList')->option([
|
||||||
|
'_alias' => '供应商列表',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
->prefix('admin.system.supplier.Supplier')
|
||||||
|
->option([
|
||||||
|
'_path' => '/supplier/supplier',
|
||||||
|
'_auth' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
->middleware(AllowOriginMiddleware::class)
|
||||||
|
->middleware(AdminTokenMiddleware::class, true)
|
||||||
|
->middleware(AdminAuthMiddleware::class)
|
||||||
|
->middleware(LogMiddleware::class);
|
||||||
Loading…
Reference in New Issue