| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\models\IntegralRecharge;
- use app\models\IntegralRechargeOrder;
- use app\models\User;
- use app\modules\admin\models\AlipayThirdForm;
- use app\modules\client\models\ApiModel;
- use app\modules\client\models\v1\order\OrderPayDataForm;
- use app\utils\Alipay\Alipay;
- use app\utils\Alipay\AlipayProfit;
- use app\utils\OrderNo;
- use app\utils\Wechat\WechatNewPay;
- use app\utils\Wechat\WechatPay;
- use EasyWeChat\Factory;
- use app\models\Store;
- /**
- * @property User $user
- * @property IntegralRechargeOrder $order
- */
- class IntegralRechargeSubmitForm extends ApiModel
- {
- public $store_id;
- public $pay_price;
- public $send_integral;
- public $pay_type;
- public $_from;
- public $recharge_id;
- /* @var Factory $wechatPay */
- public $wechatPay;
- public $order;
- public $user;
- public function rules()
- {
- return [
- [['pay_price', 'pay_type', 'recharge_id'], 'required'],
- [['send_integral'], 'number'],
- [['_from'], 'string'],
- [['pay_type'], 'in', 'range' => [1, 4]],
- [['_from'], 'in', 'range' => ['app', 'mini', 'h5']],
- ];
- }
- public function save()
- {
- $this->wechatPay = self::getWechatPay();
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $order = new IntegralRechargeOrder();
- $order->store_id = $this->store_id;
- $order->user_id = $this->user->id;
- if ($this->send_integral != 0) {
- $exists = IntegralRecharge::findOne($this->recharge_id);
- if (!$exists) {
- return [
- 'code' => 1,
- 'msg' => '充值失败,请重新充值'
- ];
- }
- }
- // 是否是平台小程序订单
- if (is_platform()) {
- $order->is_platform = 1;
- }
- $order->pay_price = $this->pay_price;
- $order->send_integral = $this->send_integral;
- $order->order_no = OrderNo::getOrderNo(OrderNo::INTEGRAL_RECHARGE);
- $order->is_pay = 0;
- $order->pay_type = $this->pay_type;
- $order->is_delete = 0;
- $order->recharge_id = $this->recharge_id;
- $order->created_at = time();
- if ($order->save()) {
- $this->order = $order;
- $body = "积分套餐充值";
- if ($this->pay_type == 1) {
- if ($this->_from == OrderPayDataForm::PAY_FROM_APP) {
- if (\Yii::$app->prod_is_dandianpu() && !Store::hasIncoming($this->store_id) && self_mini() === false) {
- $result = WechatPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, true);
- } else {
- if (is_profit_pay()) {
- $result = WechatNewPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, true);
- } else {
- $result = WechatPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, true);
- }
- }
- } else {
- $is_h5 = false;
- if (is_h5()) {
- $is_h5 = true;
- }
- if (\Yii::$app->prod_is_dandianpu() && !Store::hasIncoming($this->store_id) && self_mini() === false) {
- $result = WechatPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, false, 0, 0, $is_h5);
- } else {
- if (is_profit_pay()) {
- $result = WechatNewPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, false, 0, 0, $is_h5);
- } else {
- $result = WechatPay::orderUnify($order, OrderNo::ORDER_RECHARGE, $body, 0, false, 0, 0, $is_h5);
- }
- }
- }
- if (isset($result['code']) && $result['code'] == 1) {
- return $result;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => (object)$result['data'],
- 'res' => $result['res'],
- 'body' => $body,
- ];
- } elseif ($this->pay_type == 4) {
- $user = get_user();
- $open_user_id = $user->alipay_open_id;
- $form = new AlipayThirdForm();
- $form->method = "alipay.open.auth.token.app";
- $form->bind_store_id = get_store_id();
- if (!$open_user_id) {
- return [
- 'code' => 0,
- 'msg' => '参数获取错误'
- ];
- }
- if (!empty(get_saas_user())) {
- if (\Yii::$app->prod_is_dandianpu() && !Store::hasIncoming(get_store_id()) && self_mini() === false) {
- $res = Alipay::mini($this->order, '充值', get_saas_user(), '', '', 0, 0);
- } else {
- if (is_profit_pay('ali')) {
- $res = AlipayProfit::mini($this->order, '充值', get_saas_user(), '', '', false, 0, 0);
- } else {
- $res = Alipay::mini($this->order, '充值', get_saas_user(), '', '', 0, 0);
- }
- }
- if (isset($res['code']) && $res['code'] == 1) {
- return $res;
- }
- if (isset($res['data'])) {
- $res['data'] = array_merge($res['data'], [
- 'is_finish' => 1
- ]);
- }
- return $res;
- }
- }
- } else {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- }
- }
|