diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index 5aa96ccc9..a5c93465a 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -12,6 +12,7 @@ use app\api\validate\UserValidate; use app\common\enum\PayEnum; use app\common\logic\PaymentLogic; use app\common\logic\PayNotifyLogic; +use app\common\model\Config; use app\common\model\user\User; use app\common\model\user_create_log\UserCreateLog; use app\common\model\user_recharge\UserRecharge; @@ -80,7 +81,7 @@ class StoreController extends BaseApiController 'uid'=>$find['id'], 'staff_id'=>0, 'order_id'=>getNewOrderId('CZ'), - 'price'=>1000, + 'price'=>Config::where('name','recharge')->value('value')??1000, 'recharge_type'=>'INDUSTRYMEMBERS', ]; $order = UserRecharge::create($data); diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index f8e219939..a8826a48b 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -10,6 +10,7 @@ use app\common\model\store_branch_product\StoreBranchProduct; 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\goods\GoodsLabel; use think\facade\Db; @@ -102,11 +103,16 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L $this->searchWhere[] = ['cate_id','=',$class_all]; } } - + $off_activity=Config::where('name','off_activity')->value('value'); + if($off_activity==1){ + $field='id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch'; + }else{ + $field='id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch'; + } $this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['stock', '>', 0]; return StoreBranchProduct::where($this->searchWhere) - ->field(['id', 'product_id', 'cate_id', 'store_name', 'cost', 'store_id','vip_price','purchase', 'price', 'bar_code', 'image', 'sales', 'store_info', 'delete_time', 'unit', 'batch']) + ->field($field) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) ->order($this->sortOrder) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 2ee47e26c..4697609d3 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -10,6 +10,7 @@ use app\common\logic\BaseLogic; use app\common\logic\CapitalFlowLogic; use app\common\logic\PayNotifyLogic; use app\common\logic\StoreFinanceFlowLogic; +use app\common\model\Config; use app\common\model\dict\DictData; use app\common\model\dict\DictType; use app\common\model\order\Cart; @@ -73,9 +74,14 @@ class OrderLogic extends BaseLogic self::$activity_price = 0; //活动减少 self::$store_price = 0; //门店零售价 /** 计算价格 */ - + $off_activity=Config::where('name','off_activity')->value('value'); + if($off_activity==1){ + $field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id'; + }else{ + $field='id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id'; + } foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id')->withTrashed()->find(); + $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find(); if (!$find) { continue; } @@ -86,18 +92,20 @@ class OrderLogic extends BaseLogic $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['vip'] = 0; - if ($user && $user['user_ship'] == 1) { - //更新 会员为1的时候原价减去会员价 - $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2); - $cart_select[$k]['deduction_price'] =$deduction_price_count; - self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); - $cart_select[$k]['vip'] =1; - } - if ($user && $user['user_ship'] == 4) { - //更新 为4商户的时候减去商户价格 - $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); - $cart_select[$k]['deduction_price'] =$deduction_price_count; - self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + if($off_activity!=1){ + if ($user && $user['user_ship'] == 1) { + //更新 会员为1的时候原价减去会员价 + $deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + $cart_select[$k]['vip'] =1; + } + if ($user && $user['user_ship'] == 4) { + //更新 为4商户的时候减去商户价格 + $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); + $cart_select[$k]['deduction_price'] =$deduction_price_count; + self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); + } } //利润 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 54b7076d6..7450440c6 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -7,6 +7,7 @@ use app\common\enum\OrderEnum; use app\common\enum\PayEnum; use app\common\enum\user\UserShipEnum; use app\common\enum\YesNoEnum; +use app\common\model\Config; use app\common\model\dict\DictType; use app\common\model\finance\CapitalFlow; use app\common\model\finance\PayNotifyLog; @@ -260,9 +261,9 @@ class PayNotifyLogic extends BaseLogic $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { //充值 - $orderRe = UserRecharge::where('order_id',$orderSn)->findOrEmpty(); - if($orderRe->isEmpty() || $orderRe->status == -1){ - return true; + $orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); + if ($orderRe->isEmpty() || $orderRe->status == -1) { + return true; } $orderRe->status = -1; $orderRe->refund_price = $orderRe->price; @@ -283,8 +284,8 @@ class PayNotifyLogic extends BaseLogic $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); $deal_money = bcdiv($extra['amount']['refund'], 100, 2); - if (in_array($order['pay_type'],[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){ - if($order['pay_type'] == PayEnum::BALANCE_PAY){//用户余额 + if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 $user->now_money = bcadd($user->now_money, $deal_money, 2); $user->save(); //增加数量 @@ -292,7 +293,7 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); } - if($order['pay_type'] == PayEnum::PURCHASE_FUNDS){//采购款 + if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款 $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); $user->save(); //增加数量 @@ -300,13 +301,12 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); } - } //微信日志 user_order_refund - $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money,'',1); + $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); //处理财务流水退还 self::store_finance_back($orderSn); - self::addStock($order['id']);//微信 + self::addStock($order['id']); //微信 return true; // self::afterPay($order,$extra['transaction_id']); } @@ -322,18 +322,17 @@ class PayNotifyLogic extends BaseLogic */ public static function store_finance_back($orderSn) { - $data = StoreFinanceFlow::where('order_sn',$orderSn) - ->where(['financial_pm'=>1]) + $data = StoreFinanceFlow::where('order_sn', $orderSn) + ->where(['financial_pm' => 1]) ->select()->toArray(); - foreach ($data as &$value){ + foreach ($data as &$value) { unset($value['id']); - $value['financial_record_sn']=(new StoreFinanceFlowLogic)->getSn(); - $value['financial_pm']=0; - $value['financial_type']= OrderEnum::PAY_BACK; - $value['create_time']=time(); + $value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn(); + $value['financial_pm'] = 0; + $value['financial_type'] = OrderEnum::PAY_BACK; + $value['create_time'] = time(); } (new StoreFinanceFlow)->saveAll($data); - } /** @@ -358,7 +357,7 @@ class PayNotifyLogic extends BaseLogic $order->save(); //日志记录 $model = new StoreCashFinanceFlow(); - $model->store_id = $order['store_id']??0; + $model->store_id = $order['store_id'] ?? 0; $model->cash_price = $order->pay_price; $model->receivable = $order->pay_price; $model->remark = '退款'; @@ -376,9 +375,9 @@ class PayNotifyLogic extends BaseLogic * @param $extra * @return true */ - public static function recharge_cash_refund($orderId,$extra = []) + public static function recharge_cash_refund($orderId, $extra = []) { - $order = UserRecharge::where('id',$orderId)->findOrEmpty(); + $order = UserRecharge::where('id', $orderId)->findOrEmpty(); if ($order->isEmpty() || $order->status == -1) { return true; } @@ -515,6 +514,27 @@ class PayNotifyLogic extends BaseLogic { $financeLogic = new StoreFinanceFlowLogic(); $user_sing = new UserSign(); + $off_activity = Config::where('name', 'off_activity')->value('value'); + if ($off_activity == 1) { + //-----活动价结算更改 + $financeLogic->order = $order; + $financeLogic->user = ['uid' => $order['uid']]; + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + if ($order['uid'] > 0) { + $user_number = bcmul($order['pay_price'], '0.10', 2); + $sing = [ + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '购买商品获得兑换券', + 'store_id' => $order['store_id'], + 'number' => $user_number, + ]; + $user_sing->save($sing); + } + return false; + } $vipFen = 0; if ($order['uid'] > 0) { // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 @@ -896,7 +916,7 @@ class PayNotifyLogic extends BaseLogic $updateData[] = [ 'id' => $StoreBranchProduct['id'], 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], -// 'sales' => ['inc', $v['cart_num']] + // 'sales' => ['inc', $v['cart_num']] ]; } } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index fa80d2f0f..4b7295af4 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -345,12 +345,6 @@ class StoreOrderController extends BaseAdminController */ public function rechange_amount() { - // $order = UserRecharge::where('order_id','CZ1719052252643357')->find(); - // $order['pay_price'] = $order['price']; - // d(1); - // PayNotifyLogic::handle('recharge', $order['order_id'], $order); - - // d(1); $pay_type = $this->request->post('pay_type'); $auth_code = $this->request->post('auth_code'); //微信支付条码 if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {