first commit
This commit is contained in:
101
app/adminapi/logic/goods/GoodsRecordLogic.php
Normal file
101
app/adminapi/logic/goods/GoodsRecordLogic.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\logic\goods;
|
||||
|
||||
|
||||
use app\common\model\goods\{GoodsRecord,Goods};
|
||||
use app\common\model\member\UserMember;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use app\common\service\{UtilsService,FileService};
|
||||
|
||||
|
||||
/**
|
||||
* 抢单记录逻辑
|
||||
* Class GoodsRecordLogic
|
||||
* @package app\adminapi\logic\goods
|
||||
*/
|
||||
class GoodsRecordLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 删除抢单记录
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/19 02:29
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return GoodsRecord::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 派单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/19 02:29
|
||||
*/
|
||||
public static function dispatch(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = GoodsRecord::where(['id' => $params['id']])->findOrEmpty();
|
||||
|
||||
if ($order->isEmpty()) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
$goods = Goods::where(['id' => $params['goods_id']])->findOrEmpty();
|
||||
if ($goods->isEmpty()) {
|
||||
throw new \Exception('商品不存在');
|
||||
}
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($goods['langs'],$order['lang']);
|
||||
$goods['title'] = $data['title'];
|
||||
|
||||
//查询会员等级
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($order['user_id']);
|
||||
$member = UserMember::where(['id' => $member_id])->findOrEmpty();
|
||||
|
||||
//数量
|
||||
$num = $params['num'];
|
||||
|
||||
//计算佣金
|
||||
$commission = round($goods['money'] * $num * $member['commission']/100,2);
|
||||
|
||||
GoodsRecord::update([
|
||||
'id' => $params['id'],
|
||||
'goods_id' => $goods['id'],
|
||||
'goods_title' => $goods['title'],
|
||||
'goods_image' => FileService::setFileUrl($goods['image']) ,
|
||||
'unit_price' => $goods['money'],
|
||||
'num' => $num,
|
||||
'money' => $goods['money'] * $num,
|
||||
'commission' => $commission,
|
||||
'status' => 4
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user