diff --git a/app/admin/logic/user/UserLogic.php b/app/admin/logic/user/UserLogic.php index a88acd7fc..6ec63f14e 100644 --- a/app/admin/logic/user/UserLogic.php +++ b/app/admin/logic/user/UserLogic.php @@ -17,6 +17,7 @@ use app\common\enum\user\UserTerminalEnum; use app\common\logic\BaseLogic; use app\common\model\user\User; use app\common\model\user\UserAddress; +use app\common\model\user\UserRecharge; use think\facade\Db; use app\common\service\FileService; use Webman\Config; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index e8eefc5cf..617e9ea43 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -28,11 +28,11 @@ use Webman\RedisQueue\Redis; class PayNotifyLogic extends BaseLogic { - public static function handle($action, $orderSn, $extra = []) + public static function handle($action, $orderSn, $extra = [], $type = 'wechat') { Db::startTrans(); try { - if ($action != 'cash_pay' && $action != 'balancePay'&& $action != 'purchase_funds') { + if ($action != 'cash_pay' && $action != 'balancePay' && $action != 'purchase_funds') { $payNotifyLogLogic = new PayNotifyLogLogic(); if ($action == 'refund') { $payNotifyLogLogic->insert($action, $extra, PayNotifyLog::TYPE_REFUND); @@ -40,7 +40,7 @@ class PayNotifyLogic extends BaseLogic $payNotifyLogLogic->insert($action, $extra); } } - self::$action($orderSn, $extra); + self::$action($orderSn, $extra, $type); Db::commit(); return true; } catch (\Exception $e) { @@ -115,7 +115,6 @@ class PayNotifyLogic extends BaseLogic self::afterPay($order); Redis::send('push-platform-print', ['id' => $order['id']], 60); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - } /** @@ -150,11 +149,6 @@ class PayNotifyLogic extends BaseLogic } self::afterPay($order, $extra['transaction_id']); - //活动期间消费 - $check = DictType::where('type', 'activities')->find(); - if (isset($check) && $check['status'] == 1 && in_array($order->pay_type, [9, 17]) == false && $user['user_ship'] == 0) { - self::dealChange($order['uid']); - } if ($order->pay_type == 9) { $extra['create_time'] = $order['create_time']; @@ -191,13 +185,17 @@ class PayNotifyLogic extends BaseLogic /** * 充值 */ - public static function recharge($orderSn, $extra = []) + public static function recharge($orderSn, $extra = [], $type = 'wechat') { $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { return true; } - $price = bcdiv($extra['amount']['payer_total'], 100, 2); + if ($type == 'wechat') { + $price = bcdiv($extra['amount']['payer_total'], 100, 2); + } else { + $price = $extra['buyer_pay_amount']; + } $order->price = $price; $order->paid = 1; $order->pay_time = time(); @@ -212,13 +210,16 @@ class PayNotifyLogic extends BaseLogic return true; } bcscale(2); -// $user->now_money = bcadd($user->now_money, $price, 2);//v.1 + // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 + //更新等级 + if ($price >= 1000) { + $user->user_ship = 1; //v.1 + } $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->save(); - //更新等级 - self::dealLevel($uid, $user->total_recharge_amount); + if (!empty($extra['payer']['openid'])) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 5); } @@ -296,13 +297,13 @@ class PayNotifyLogic extends BaseLogic $financeLogic->user = ['uid' => $order['uid']]; // if ($order->pay_type != 9 || $order->pay_type != 10) { $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY); //用户订单支付 - $count_frees=0; + $count_frees = 0; //商户应该获得的钱 每个商品的price-ot_price 利润 // if (isset($order->profit) && $order->profit > 0) { //平台手续费 $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); - $count_frees=bcadd($count_frees,$fees,2); + $count_frees = bcadd($count_frees, $fees, 2); $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, $order['pay_type']); //平台手续费 $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 @@ -312,7 +313,7 @@ class PayNotifyLogic extends BaseLogic $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 $store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); - $count_frees=bcadd($count_frees,$store_profit,2); + $count_frees = bcadd($count_frees, $store_profit, 2); if ($deposit > 0) { if ($deposit > $store_profit) { $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); @@ -328,78 +329,53 @@ class PayNotifyLogic extends BaseLogic if ($order['spread_uid'] > 0) { $financeLogic->other_arr['vip_uid'] = $order['spread_uid']; $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); - $count_frees=bcadd($count_frees,$fees,2); + $count_frees = bcadd($count_frees, $fees, 2); $financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); //vip订单获得 $financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); } $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); - $count_frees=bcadd($count_frees,bcmul($fees,3,2),2); - $village_uid=0; - $brigade_uid=0; + $count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2); + $village_uid = 0; + $brigade_uid = 0; //查询用户对应的村长和队长 - if($order['uid']>0){ - $address=UserAddress::where(['uid'=>$order['uid'],'is_default'=>1])->find(); - if($address){ - $arr1=UserAddress::where(['village'=>$address['village'],'is_default'=>1])->column('uid'); - if($arr1){ - $village_uid=User::where('id','in',$arr1)->where('user_ship',2)->value('id'); + if ($order['uid'] > 0) { + $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); + if ($address) { + $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); + if ($arr1) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); } - $arr2=UserAddress::where(['village'=>$address['village'],'brigade'=>$address['brigade'],'is_default'=>1])->column('uid'); - if($arr2){ - $brigade_uid=User::where('id','in',$arr1)->where('user_ship',3)->value('id'); + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); } } } //村长获得 - if($village_uid>0){ + if ($village_uid > 0) { $financeLogic->other_arr['vip_uid'] = $village_uid; } - $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); + $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //队长获得 - if($brigade_uid>0){ + if ($brigade_uid > 0) { $financeLogic->other_arr['vip_uid'] = $brigade_uid; } - $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); + $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //其他获得 - $financeLogic->other_arr['vip_uid']=0; - $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); + $financeLogic->other_arr['vip_uid'] = 0; + $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); } //供应链订单获得 - $financeLogic->in($transaction_id, $count_frees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); + $financeLogic->in($transaction_id, $count_frees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, $order['pay_type']); $financeLogic->out($transaction_id, $count_frees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); // } $financeLogic->save(); // } } - //等级处理 - public static function dealLevel($uid, $total_money) - { - $userShip = UserShip::where('limit', '<=', $total_money) - ->field('id,title,limit') - ->order('limit', 'desc') - ->find(); - $info = User::where('id', $uid)->findOrEmpty(); - if ($info && $userShip) { - if ($info->user_ship != $userShip['id']) { - $info->user_ship = $userShip['id']; - $info->save(); - } - } - return true; - } - - //处理活动期间直接改用户的等级 - public static function dealChange($uid) - { - User::where('id', $uid)->update(['user_ship' => UserShipEnum::LEVEL_ONE]); - return true; - } - - /** * 回调日志 * @param $order diff --git a/app/queue/redis/CodePaySend.php b/app/queue/redis/CodePaySend.php index c3b33c55b..d944b9eec 100644 --- a/app/queue/redis/CodePaySend.php +++ b/app/queue/redis/CodePaySend.php @@ -30,7 +30,11 @@ class CodePaySend implements Consumer ]; $res = $pay->wechat->query($order); if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { - PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); + if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ + PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + }else{ + PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); + } }else{ throw new BusinessException('订单支付中', 200); } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 02af03752..47147921c 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -13,6 +13,7 @@ use app\common\logic\SystemStoreStaffLogic; use app\store\controller\BaseAdminController; use app\common\logic\store_order\StoreOrderLogic; use app\common\model\store_order\StoreOrder; +use app\common\model\user_recharge\UserRecharge; use app\store\validate\store_order\StoreOrderValidate; use support\Log; use Webman\RedisQueue\Redis; @@ -290,6 +291,56 @@ class StoreOrderController extends BaseAdminController return $this->success('ok',$data); } - + /** + * vip充值 + */ + public function rechange_amount() + { + $pay_type = $this->request->post('pay_type'); + $auth_code = $this->request->post('auth_code'); //微信支付条码 + if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) { + return $this->fail('支付条码不能为空'); + } + $params = $this->request->post(); + $data=[ + 'store_id'=>$this->adminInfo['store_id'], + 'uid'=>$params['uid'], + 'staff_id'=>$this->adminId, + 'order_id'=>getNewOrderId('CZ'), + 'price'=>$params['price'], + ]; + $order = UserRecharge::create($data); + switch ($pay_type) { + case PayEnum::WECHAT_PAY_BARCODE: + //微信条码支付 + $result = PaymentLogic::codepay($auth_code, $order); + if (PaymentLogic::hasError()) { + return $this->fail(PaymentLogic::getError(), $params); + } + if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { + PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); + } else { + Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']); + return $this->success('用户支付中'); + } + return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]); + case PayEnum::ALIPAY_BARCODE: + //支付宝条码支付 + $result = PaymentLogic::ali_auth_code($auth_code, $order); + if (PaymentLogic::hasError()) { + return $this->fail(PaymentLogic::getError(), $params); + } + if ($result['msg'] !== 'Success') { + return $this->success('用户支付中'); + } + PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result,'ali'); + + $result['create_time'] = $order['create_time']; + return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]); + default: + return $this->fail('支付方式错误'); + } + return $this->fail('支付失败'); + } } diff --git a/app/store/controller/user/AddressController.php b/app/store/controller/user/AddressController.php index 7406b81cc..b3a74cf8b 100644 --- a/app/store/controller/user/AddressController.php +++ b/app/store/controller/user/AddressController.php @@ -1,14 +1,14 @@ dataLists(new UserAddressList()); diff --git a/app/store/controller/user/UserController.php b/app/store/controller/user/UserController.php index 4a6083856..35b8737e5 100644 --- a/app/store/controller/user/UserController.php +++ b/app/store/controller/user/UserController.php @@ -30,7 +30,6 @@ class UserController extends BaseAdminController } - public function detail() { $params = (new UserValidate())->goCheck('detail');