Merge pull request 'dev' (#199) from dev into main

Reviewed-on: #199
This commit is contained in:
mkm 2024-09-09 23:15:24 +08:00
commit f47afdd7b1
6 changed files with 281 additions and 148 deletions

View File

@ -13,6 +13,8 @@ use app\common\lists\ListsExcelInterface;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/**
* 订单购物详情列表
@ -49,11 +51,26 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
public function lists(): array
{
return StoreOrderCartInfo::where($this->searchWhere)
->field('oid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
->field('oid,uid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
if($find){
if($item['uid']>0){
$user=User::where('id',$item['uid'])->field('real_name,mobile')->find();
if($user){
if($user['real_name']!=''){
$item['nickname']=$user['real_name'];
}else{
$item['nickname']=$user['mobile'];
}
}else{
$item['nickname']='无';
}
}else{
$item['nickname']='无';
}
$item['image']=$find['image'];//商品图片
$item['system_store']=SystemStore::where('id',$item['store_id'])->value('name')??"";
$item['store_name']=$find['store_name'];//商品名称
$item['store_info']=$find['store_info'];//商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
@ -64,6 +81,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
$item['cate_name']='';//商品图片
$item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介)
$item['nickname']='';
$item['system_store']='';
}
return $item; //返回处理后的数据。
})
@ -108,12 +127,15 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
{
$data=[
'store_name' => '商品名称',
'system_store' => '门店',
'nickname' => '用户',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
'create_time' => '时间',
];
return $data;
}

View File

@ -62,15 +62,50 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
}
}
return StoreProduct::where($this->searchWhere)
->field(['id', 'image', 'store_info','store_name', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information'])
->field(['id', 'image', 'store_info', 'store_name', 'top_cate_id', 'two_cate_id', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) {
$item['bar_code_two'] = $item['bar_code'];
if ($item['bar_code'] == 0) {
$item['bar_code_two'] = '';
}
$item['bar_code'] = '';
$item['unit_names'] = '称重商品';
} else {
if (strlen($item['bar_code']) < 10) {
$item['bar_code_two'] = $item['bar_code'];
if ($item['bar_code'] == 0) {
$item['bar_code_two'] = '';
}
$item['bar_code'] = '';
}
$item['unit_names'] = '标准商品';
}
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
$item['stock'] = bcadd($nums, $stock);
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
$cate_name = '';
$category_top = StoreCategory::where('id', $item['top_cate_id'])->value('name');
if ($category_top != '') {
$cate_name = '/' . $category_top;
}
if (!$category_top) {
$category_two = StoreCategory::where('id', $item['two_cate_id'])->value('name');
if ($category_two != '') {
$cate_name = $cate_name . '/' . $category_two;
}
}
$category_three = StoreCategory::where('id', $item['cate_id'])->value('name');
if ($category_three) {
$cate_name = $cate_name . '/' . $category_three;
}
$item['cate_name'] = $cate_name;
// $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item;
})?->toArray();
}
@ -84,8 +119,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
*/
public function count(): int
{
$export=$this->request->get('export');
if($export==1){
$export = $this->request->get('export');
if ($export == 1) {
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
@ -123,15 +158,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
{
$data = [
'id' => '商品id',
'unit_names' => '计价方式',
'store_name' => '商品名称',
'cate_name'=>'分类',
'unit_name'=>'单位',
'store_info'=>'规格',
'cate_name' => '分类',
'unit_name' => '单位',
'store_info' => '规格',
'stock' => '库存',
'purchase' => '采购价',
'cost' => '商户',
'price' => '零售',
'bar_code' => '条码',
'bar_code_two' => '自编码',
];
return $data;
}

View File

@ -44,8 +44,17 @@ class IndexController extends BaseApiController
public function index()
{
return json(1);
$financeFlow = new StoreFinanceFlow();
$financeFlowLogic = new StoreFinanceFlowLogic();
$select_1 = $financeFlow->where('id',16197)->select();
foreach ($select_1 as $k => $v) {
if ($v['other_uid'] > 0) {
$financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']);
}
}
}

View File

@ -31,15 +31,14 @@ class CommissionProductLogic extends BaseLogic
if ($user_ship == 5) {
$top_cate_id = $product['top_cate_id'];
if ($top_cate_id == 15189) {
$this->b($find, $order, $product,$user_ship);
$this->b($find, $order, $product, $user_ship);
return true;
}
} elseif($user_ship==0) {
$this->b($find, $order, $product,$user_ship);
} elseif ($user_ship == 0) {
$this->b($find, $order, $product, $user_ship);
return true;
}else{
} else {
$this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
}
}
@ -52,190 +51,256 @@ class CommissionProductLogic extends BaseLogic
*/
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{
// $rose = bcdiv($product['rose'], 100, 2);
if($user_ship==4){
$total_price = bcmul($product['cost'], $find['cart_num']);
$price=$product['cost'];
}else{
$total_price = bcmul($product['price'], $find['cart_num']);
$price=$product['price'];
}
// $Distribution = Distribution::where('rate', $rose)->find();
//门店
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$price = $product['purchase'];
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长
$platform_number = bcmul($purchase_price, 0.02, 2); //平台
$attrition_number = bcmul($purchase_price, 0.01, 2); //损耗
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
//零售-供货价
$number3 = bcsub($total_price, $purchase_price, 2);
$number4 = bcadd($attrition_number, $number2, 2);
//会员
if ($order['spread_uid'] > 0 || $user_ship > 0) {
if (in_array($user_ship, [2, 3])) {
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
$data[] = [
'nickname' => '门店',
'nickname' => '会员',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'other_uid' => $order['spread_uid'],
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => bcmul($total_price, 0.05, 2),
'number' => $vip_number,
'oid' => $order['id'],
'type' => 1,
'type' => 0,
'status' => 1,
];
//平台
$number4=bcadd($number4, $vip_number, 2);
} else {
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
$data[] = [
'nickname' => '平台',
'nickname' => '会员',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.07,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
];
$number4=bcadd($number4, $vip_number, 2);
}
}
//门店利润
if ($number3 <= 0) {
$store_number = 0;
} else {
$store_number = bcsub($number3, $number4, 2);
}
//队长
$data[] = [
'nickname' => '零售队长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => bcmul($total_price, 0.02, 2),
'oid' => $order['id'],
'type' => 2,
'status' => 1,
];
//村长
$data[] = [
'nickname' => '村长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'price' => $price,
'other_uid' => $village_uid,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => bcmul($total_price, 0.01, 2),
'oid' => $order['id'],
'type' => 3,
'status' => 1,
];
//队长
$data[] = [
'nickname' => '队长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'price' => $price,
'other_uid' => $brigade_uid,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => bcmul($total_price, 0.01, 2),
'number' => $brigade_number,
'oid' => $order['id'],
'type' => 4,
'status' => 1,
'is_activity' => 1,
];
//会员
// if ($user_ship == 1) {
// $uid = $order['spread_uid'];
// } else {
// $uid = 0;
// }
// $data[] = [
// 'store_id' => $order['store_id'],
// 'product_id' => $find['product_id'],
// 'other_uid' => $uid,
// 'number' => bcmul($total_price, $Distribution['user'], 2),
// 'oid' => $order['id'],
// 'type' => 0,
// 'status' => 1,
// ];
//会员
if ($order['spread_uid'] > 0 ||$user_ship>0) {
if (in_array($user_ship, [2, 3])) {
//村长
$data[] = [
'nickname' => '会员',
'nickname' => '零售村长',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'other_uid' => $order['spread_uid'],
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => bcmul($total_price, 0.05, 2),
'total_price' => $brigade_number,
'cart_num' => 0,
'rate' => 0.01,
'number' => $village_number,
'oid' => $order['id'],
'type' => 0,
'type' => 3,
'status' => 1,
'is_activity' => 1,
];
} else {
//门店
$data[] = [
'nickname' => '会员',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.07,
'number' => bcmul($total_price, 0.07, 2),
'oid' => $order['id'],
'type' => 0,
'status' => 1,
];
}
}
$data[] = [
'nickname' => '消耗',
'nickname' => '零售门店',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0,
'number' => $store_number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
'is_activity' => 1,
];
//平台
$data[] = [
'nickname' => '零售平台',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $platform_number,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
'is_activity' => 1,
];
$data[] = [
'nickname' => '零售消耗',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => bcmul($total_price, 0.01, 2),
'number' => $attrition_number,
'oid' => $order['id'],
'type' => 6,
'status' => 1,
];
(new StoreFinanceFlowProduct())->saveAll($data);
}
/**
* 商户价结算
*/
public function b($find, $order, $product,$user_ship)
public function b($find, $order, $product, $user_ship)
{
// $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['cost'], $find['cart_num']);
$price = $product['cost'];
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$price = $product['purchase'];
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长
$platform_number = bcmul($purchase_price, 0.02, 2); //平台
$attrition_number = bcmul($purchase_price, 0.01, 2); //损耗
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
//零售-供货价
$number3 = bcsub($total_price, $purchase_price, 2);
$number4 = bcadd($attrition_number, $number2, 2);
//门店利润
if ($number3 <= 0) {
$store_number = 0;
} else {
$store_number = bcsub($number3, $number4, 2);
}
//队长
$data[] = [
'nickname' => '商户价队长预留',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => $brigade_number,
'oid' => $order['id'],
'type' => 4,
'status' => 1,
'is_activity' => 1,
];
//村长
$data[] = [
'nickname' => '商户价村长预留',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $brigade_number,
'cart_num' => 0,
'rate' => 0.01,
'number' => $village_number,
'oid' => $order['id'],
'type' => 3,
'status' => 1,
'is_activity' => 1,
];
//门店
$data[] = [
'nickname' => '门店',
'nickname' => '商户价门店',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => bcmul($total_price, 0.05, 2),
'rate' => 0,
'number' => $store_number,
'oid' => $order['id'],
'type' => 1,
'status' => 1,
'is_activity' => 1,
];
//平台
$data[] = [
'nickname' => '平台',
'nickname' => '商户价平台',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.02,
'number' => bcmul($total_price, 0.02, 2),
'number' => $platform_number,
'oid' => $order['id'],
'type' => 2,
'status' => 1,
'is_activity' => 1,
];
$data[] = [
'nickname' => '消耗',
'nickname' => '商户价消耗',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => 0,
'price' => $price,
'total_price' => $total_price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.01,
'number' => bcmul($total_price, 0.01, 2),
'number' => $attrition_number,
'oid' => $order['id'],
'type' => 6,
'status' => 1,
@ -249,10 +314,10 @@ class CommissionProductLogic extends BaseLogic
// $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$price=$product['price'];
$brigade_number = bcmul($total_price, 0.02, 2);//队长
$village_number = bcmul($brigade_number, 0.1, 2);//村长
$platform_number = bcmul($total_price, 0.02, 2);//平台
$price = $product['price'];
$brigade_number = bcmul($total_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长
$platform_number = bcmul($total_price, 0.02, 2); //平台
$number1 = bcadd($brigade_number, $village_number, 2);
$number2 = bcadd($number1, $platform_number, 2);
@ -261,11 +326,10 @@ class CommissionProductLogic extends BaseLogic
$number3 = bcsub($total_price, $purchase_price, 2);
//门店利润
if($number3<=0){
if ($number3 <= 0) {
$store_number = 0;
}else{
} else {
$store_number = bcsub($number3, $number2, 2);
}
//队长

View File

@ -352,6 +352,7 @@ class PayNotifyLogic extends BaseLogic
if ($type == 1) {
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0);
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]);
} else {
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0);
$user->now_money = bcadd($user['now_money'], $money, 2);
@ -366,6 +367,7 @@ class PayNotifyLogic extends BaseLogic
if ($type == 1) {
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
$user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2);
StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]);
} else {
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1);
$user->purchase_funds = bcadd($user['purchase_funds'], $money, 2);

View File

@ -48,7 +48,6 @@ class StoreOrderLogic extends BaseLogic
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
if (empty($cart_select)) {
throw new BusinessException('购物车为空');
return false;
}
try {
self::$total_price = 0;
@ -238,7 +237,7 @@ class StoreOrderLogic extends BaseLogic
$query->field(['id', 'oid', 'product_id', 'cart_info']);
}])->where($params)->find();
if (empty($order)) {
throw new \Exception('订单不存在');
throw new BusinessException('订单不存在');
}
$order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : '';
$order['status_name'] = OrderEnum::getOrderType($order['status']) ?? '';
@ -372,7 +371,7 @@ class StoreOrderLogic extends BaseLogic
return false;
} catch (Exception $e) {
\support\Log::info($e->extra['message'] ?? $e->getMessage());
throw new \Exception($e->extra['message'] ?? $e->getMessage());
throw new BusinessException($e->getMessage());
}
}
@ -383,7 +382,7 @@ class StoreOrderLogic extends BaseLogic
$code = generateRandomCode();
$phone = User::where('id',$param['uid'])->value('mobile');
if(empty($phone)){
throw new \Exception('用户未设置手机号');
throw new BusinessException('用户未设置手机号');
}
$template = getenv('SMS_TEMPLATE');
$check =(new SmsService())->client($phone,$template,$code);