125 lines
3.0 KiB
PHP
125 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\delivery_service;
|
|
|
|
|
|
use app\common\model\delivery_service\DeliveryService;
|
|
use app\common\logic\BaseLogic;
|
|
use support\exception\BusinessException;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 配送员逻辑
|
|
* Class DeliveryServiceLogic
|
|
* @package app\admin\logic\delivery_service
|
|
*/
|
|
class DeliveryServiceLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加配送员
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/08 14:07
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
DeliveryService::create([
|
|
'uid' => $params['uid'],
|
|
'nickname' => $params['nickname'],
|
|
'phone' => $params['phone'],
|
|
'status' => $params['status']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑配送员
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/08 14:07
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
DeliveryService::where('id', $params['id'])->update([
|
|
'uid' => $params['uid'],
|
|
'nickname' => $params['nickname'],
|
|
'phone' => $params['phone'],
|
|
'status' => $params['status']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除配送员
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/08/08 14:07
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return DeliveryService::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取配送员详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2024/08/08 14:07
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return DeliveryService::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
|
|
public static function addPurchaseFunds($uid, $amount)
|
|
{
|
|
$model = DeliveryService::where('uid', $uid)->findOrEmpty();
|
|
if (!$model->isEmpty()) {
|
|
$model->purchase_funds_total = bcadd($model->purchase_funds_total, $amount, 2);
|
|
$model->current_purchase_funds = bcadd($model->current_purchase_funds, $amount, 2);
|
|
$model->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 扣减采购人员资金
|
|
* @param $uid
|
|
* @param $amount
|
|
* @return void
|
|
*/
|
|
public static function subPurchaseFunds($uid, $amount)
|
|
{
|
|
$model = DeliveryService::where('uid', $uid)->findOrEmpty();
|
|
if (!$model->isEmpty()) {
|
|
$model->current_purchase_funds = bcsub($model->current_purchase_funds, $amount, 2);
|
|
$model->save();
|
|
}
|
|
}
|
|
|
|
} |