This commit is contained in:
lewis 2025-01-04 15:20:28 +08:00
commit adf0ae1d42
11 changed files with 83 additions and 48 deletions

View File

@ -7,6 +7,7 @@ use Next\VarDumper\Dumper;
use Next\VarDumper\DumperHandler; use Next\VarDumper\DumperHandler;
use support\exception\BusinessException; use support\exception\BusinessException;
use support\exception\Handler; use support\exception\Handler;
use support\Log;
use Throwable; use Throwable;
use Webman\Http\Request; use Webman\Http\Request;
use Webman\Http\Response; use Webman\Http\Response;
@ -22,6 +23,7 @@ class ExceptionHandler extends Handler
return \response(self::convertToHtml($exception)); return \response(self::convertToHtml($exception));
}elseif ($exception instanceof BusinessException) { }elseif ($exception instanceof BusinessException) {
if ($request->expectsJson()) { if ($request->expectsJson()) {
Log::error('BusinessException:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]); return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]);
} }
return response($exception->getMessage()); return response($exception->getMessage());
@ -35,9 +37,12 @@ class ExceptionHandler extends Handler
$error['file'] = $exception->getFile(); $error['file'] = $exception->getFile();
$error['line'] = $exception->getLine(); $error['line'] = $exception->getLine();
} }
Log::error('Exception:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
return response(json_encode($error, JSON_UNESCAPED_UNICODE)); return response(json_encode($error, JSON_UNESCAPED_UNICODE));
} }
// 非json请求则返回一个页面 // 非json请求则返回一个页面
Log::error('other:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile()); return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile());
} }
} }

View File

@ -1,20 +0,0 @@
<?php
namespace app;
use support\exception\BusinessException;
use Webman\Http\Request;
use Webman\Http\Response;
class MyBusinessException extends BusinessException
{
public function render(Request $request): ?Response
{
// json请求返回json数据
if ($request->expectsJson()) {
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage(),'show'=>1]);
}
// 非json请求则返回一个页面
return new Response(200, [], $this->getMessage());
}
}

View File

@ -411,7 +411,7 @@ class BeforehandOrderLogic extends BaseLogic
'admin_id' => $admin_id, 'admin_id' => $admin_id,
'total_price' => $arr['total_price'], 'total_price' => $arr['total_price'],
'price' => $arr['price'], 'price' => $arr['price'],
'vip_price' => $price==0?$arr['price']:$price, 'vip_price' => $price,
'purchase' => $arr['purchase'], 'purchase' => $arr['purchase'],
'oid' => $res['id'], 'oid' => $res['id'],
'code' => $res['code'], 'code' => $res['code'],
@ -870,10 +870,10 @@ class BeforehandOrderLogic extends BaseLogic
if($order['uid']>0){ if($order['uid']>0){
$user_ship = User::where('id', $order['uid'])->value('user_ship'); $user_ship = User::where('id', $order['uid'])->value('user_ship');
if($user_ship==0){ if($user_ship==0){
throw new BusinessException('用户id不能为0'); throw new BusinessException('用户角色id不能为0');
} }
}else{ }else{
throw new BusinessException('用户id不能为0'); throw new BusinessException('该订单没选择会员用户');
} }
$total_price = 0; $total_price = 0;
$pay_price = 0; $pay_price = 0;

View File

@ -346,31 +346,28 @@ class WarehouseProductLogic extends BaseLogic
//减少 //减少
private static function decStock($res) private static function decStock($res)
{ {
$res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id']) ->where('product_id', $res['product_id'])->find();
->dec('nums', $res['nums']) $res1->save(['nums'=>bcsub($res1['nums'], $res['nums'],2)]);
->save(); SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], -1, Request()->url());
SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], -1, Request()->url());
$res2 = StoreBranchProduct::where('id', $res['id']) $res2 = StoreBranchProduct::where('id', $res['id'])->find();
->dec('stock', $res['nums']) $res2->save(['stock'=>bcsub($res2['stock'], $res['nums'],2)]);
->update();
SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], -1, Request()->url()); SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], -1, Request()->url());
} }
//增加 //增加
private static function incStock($res, $params) private static function incStock($res, $params)
{ {
$res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id']) ->where('product_id', $res['product_id'])
->inc('nums', $params['nums']) ->find();
->save(); $res1->save(['nums'=>bcadd($res1['nums'], $params['nums'],2)]);
SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], 1, Request()->url());
SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], 1, Request()->url());
$res2 = StoreBranchProduct::where('id', $res['id']) $res2 = StoreBranchProduct::where('id', $res['id'])->find();
->inc('stock', $params['nums']) $res2->save(['stock'=>bcadd($res2['stock'], $params['nums'],2)]);
->save();
SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], 1, Request()->url()); SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], 1, Request()->url());
} }
} }

View File

@ -9,7 +9,6 @@ use app\common\enum\AdminTerminalEnum;
use app\common\model\auth\Admin; use app\common\model\auth\Admin;
use app\common\service\ConfigService; use app\common\service\ConfigService;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
use app\MyBusinessException;
use support\exception\BusinessException; use support\exception\BusinessException;
use Webman\Config; use Webman\Config;

View File

@ -9,8 +9,7 @@ use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\MyBusinessException;
use think\Exception;
/** /**

View File

@ -21,7 +21,34 @@ class StoreBranchProduct extends BaseModel
use SoftDelete; use SoftDelete;
protected $name = 'store_branch_product'; protected $name = 'store_branch_product';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public $ignoreLogFields = [
'top_cate_id',
'two_cate_id',
'cate_id',
'store_name',
'image',
'price',
'vip_price',
'cost',
'purchase',
'total_price',
'store_info',
'keyword',
'bar_code',
'rose',
'status',
'product_type',
'unit',
'batch',
'store_batch',
'sort',
'label_id',
'is_lack',
'manufacturer_information',
'status',
'create_time',
'update_time',
];
public function unitName() public function unitName()

View File

@ -18,7 +18,34 @@ class WarehouseProduct extends BaseModel
use SoftDelete; use SoftDelete;
protected $name = 'warehouse_product'; protected $name = 'warehouse_product';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public $ignoreLogFields = [
'price',
'total_price',
'status',
'pay_type',
'is_pay',
'vip_price',
'cost',
'purchase',
'total_price',
'mark',
'after_nums',
'before_nums',
'batch',
'enter_admin_id',
'admin_id',
'financial_pm',
'expiration_date',
'manufacture',
'code',
'oid',
'unit',
'store_id',
'supplier_id',
'warehouse_id',
'create_time',
'update_time',
];
public static function onBeforeWrite($data) public static function onBeforeWrite($data)
{ {
try { try {

View File

@ -18,7 +18,11 @@ class WarehouseProductStorege extends BaseModel
use SoftDelete; use SoftDelete;
protected $name = 'warehouse_product_storege'; protected $name = 'warehouse_product_storege';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public $ignoreLogFields = [
'price',
'total_price',
'update_time',
];
public static function onBeforeWrite($data) public static function onBeforeWrite($data)
{ {
try { try {

View File

@ -20,8 +20,6 @@ use app\common\model\system_store\SystemStoreStaff;
use app\store\service\AdminTokenService; use app\store\service\AdminTokenService;
use app\common\model\auth\AdminRole; use app\common\model\auth\AdminRole;
use app\common\service\FileService; use app\common\service\FileService;
use app\MyBusinessException;
use think\facade\Db;
use Webman\Config; use Webman\Config;
/** /**

View File

@ -9,7 +9,6 @@ use app\common\model\store_product\StoreProduct;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\MyBusinessException;
use support\exception\BusinessException; use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;