feat: 修改购物车商品查询逻辑和订单逻辑,根据用户身份调整商品价格计算方式,并更新相关文档

This commit is contained in:
mkm 2024-07-08 17:24:50 +08:00
parent 74c0456f1a
commit f6c8b7865e
4 changed files with 84 additions and 80 deletions

View File

@ -64,6 +64,10 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
->toArray();
$off_activity = Config::where('name', 'off_activity')->value('value');
$this->off_activity=$off_activity;
$user_ship = User::where('id', $userId)->value('user_ship');
if (in_array($user_ship, [4, 5, 6, 7])) {
$off_activity=1;
}
foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']])
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price')

View File

@ -3,7 +3,7 @@
namespace app\api\lists\product;
use app\admin\lists\BaseAdminDataLists;
use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType;
@ -12,6 +12,7 @@ use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate;
use app\common\model\Config;
use app\common\model\user\User;
//use app\common\model\goods\GoodsLabel;
use think\facade\Db;
@ -20,7 +21,7 @@ use think\facade\Db;
* Class goods
* @package app\api\goods
*/
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
class ProductLists extends BaseApiDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
{
@ -36,7 +37,6 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
'=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
}
/**
* @notes 设置支持排序字段
@ -71,17 +71,6 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function lists(): array
{
// $class_all = $this->request->get('class_all');
// if ($class_all) {
// //查3级别的
// $arr = Cate::where('pid', $class_all)->column('id');
// if ($arr) {
// $arr2 = Cate::where('pid', 'in', $arr)->column('id');
// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
// } else {
// $this->searchWhere[] = ['cate_id', '=', $class_all];
// }
// }
$order = $this->request->get('order', '');
$field = $this->request->get('field', '');
if (empty($order) || empty($field)) {
@ -116,20 +105,26 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
}
public function extend()
{
// $off_activity = Config::where('name', 'off_activity')->value('value');
// if($off_activity==1){
// $data=[
// 'off_activity' => $off_activity,
// 'price' => 'cost',
// 'op_price' => 'price',
// ];
// }else{
$price = 'price';
$op_price = 'price';
$off_activity = 0;
if ($this->userId > 0) {
$user_ship = User::where('id', $this->userId)->value('user_ship');
if (in_array($user_ship, [4, 5, 6, 7])) {
$price = 'cost';
$op_price = 'price';
}
}
$off_activity = Config::where('name', 'off_activity')->value('value');
if ($off_activity == 1) {
$price = 'cost';
$op_price = 'price';
}
$data = [
'off_activity' => 0,
'price' => 'price',
'op_price' => 'price',
'off_activity' => $off_activity,
'price' => $price,
'op_price' => $op_price,
];
// }
return $data;
}
}

View File

@ -94,11 +94,15 @@ class OrderLogic extends BaseLogic
}
unset($cart_select[$k]['id']);
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
// if ($off_activity == 1) {
// $price = $find['cost'];
// } else {
if ($off_activity == 1) {
$price = $find['cost'];
} else {
if ($user && in_array($user['user_ship'], [4, 5, 6, 7])) {
$price = 'cost';
} else {
$price = $find['price'];
// }
}
}
$cart_select[$k]['price'] = $price;
$cart_select[$k]['cost'] = $find['cost'];
$cart_select[$k]['vip'] = 0;
@ -534,7 +538,8 @@ class OrderLogic extends BaseLogic
(new StoreProductLog())->update(
[
'store_id' => $params['store_id']
], ['oid' => $order['id']]
],
['oid' => $order['id']]
);
(new StoreOrderCartInfo())->update([
'verify_code' => $params['verify_code'] . '-1',

View File

@ -588,7 +588,7 @@ class PayNotifyLogic extends BaseLogic
}
//积分写入
if(in_array($order['pay_type'],[3,7,9,13,17])&&$order['uid']>0){
if(isset($user) && $user['user_ship']==0){
UserSignLogic::OrderWrite($order);
}
if ($off_activity == 1) {
@ -644,10 +644,10 @@ class PayNotifyLogic extends BaseLogic
}
switch ($user_ship) {
case 1: // 厨师
case 4: // 商户
case 5: // 种养殖
case 6: // 酒店
case 7: // 食堂
//case 4: // 商户
//case 5: // 种养殖
// case 6: // 酒店
// case 7: // 食堂
case 8: // 一条龙
CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
break;