| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models\purchase;
- use app\models\Admin;
- use app\models\Option;
- use app\models\RechargeReOrder;
- use app\models\Store;
- use app\modules\admin\models\PlatformForm;
- use yii\base\Model;
- use app\models\PurchaseReOrder;
- use app\models\User;
- use app\modules\client\models\ApiModel;
- use app\modules\client\models\v1\order\OrderPayDataForm;
- use app\utils\Alipay\Alipay;
- use app\utils\OrderNo;
- use app\utils\Wechat\WechatNewPay;
- use app\utils\Wechat\WechatPay;
- use EasyWeChat\Factory;
- use app\utils\Wechat\WechatBusinessPay;
- use app\models\StoreCloud;
- use app\utils\Wechat\WechatAlliancePay;
- class BalanceForm extends Model
- {
- public $saas_id;
- public $store_id;
- public $pay_price;
- public $send_price = 0;
- public $pay_type;
- public $_from;
- public $order;
- public $user;
- public function rules()
- {
- return [
- [['send_price'], 'number'],
- [['_from'], 'string'],
- [['pay_type'],'in','range'=>[1, 4]],
- [['_from'], 'in', 'range' => ['app', 'mini', 'h5']],
- [['saas_id', 'user', 'order', 'pay_price','pay_type'], 'safe'],
- ];
- }
- public function payData()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $orderType = OrderNo::ORDER_PURCHASE_RE;
- $order = new PurchaseReOrder();
- $order->store_id = $this->store_id;
- $order->user_id = $this->user->id;
- $order->saas_id = $this->saas_id;
- // 是否是平台小程序订单
- if (is_platform()) {
- $order->is_platform = 1;
- }
- $order->pay_price = $this->pay_price;
- $order->send_price = $this->send_price;
- $order->order_no = OrderNo::getOrderNo(OrderNo::ORDER_PURCHASE_RE);
- $order->is_pay = 0;
- $order->pay_type = $this->pay_type;
- $order->is_delete = 0;
- $order->created_at = time();
- // var_dump($this);die;
- if ($order->save()) {
- $this->order = $order;
- $body = "充值";
- if ($this->pay_type == 1) {
- // $result = WechatAlliancePay::orderUnify($this->order,$orderType, $body, 0, false, 0);
- $result = WechatBusinessPay::orderUnify($this->order, $orderType, $body, 0, false, 0);
- if (isset($result['code']) && $result['code'] == 1) {
- return $result;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => (object)$result['data'],
- 'res' => $result['res'],
- 'body' => $body,
- ];
- }
- $goods_names = $body;
- $res = Alipay::mini($this->order, $goods_names, $this->user, '', '', 0, 0);
- if ($res['code'] != 0) {
- return $res;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res['data'],
- 'res' => $res['data'],
- 'body' => $body,
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- }
- public function payDataLeague()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $orderType = OrderNo::ORDER_PURCHASE_RE;
- $order = new RechargeReOrder();
- $order->user_id = $this->user->id;
- $order->saas_id = $this->saas_id;
- // 是否是平台小程序订单
- if (is_platform()) {
- $order->is_platform = 1;
- }
- $order->pay_price = $this->pay_price;
- // $store_recharge_profit_model = Option::findOne(['name' => 'store_recharge_profit']);
- // $profit = $store_recharge_profit_model->value;
- $admin = Admin::findOne(['saas_user_id' => $this->saas_id, 'is_delete' => 0, 'type' => 'store']);
- $store = Store::findOne($admin->type_id);
- $order->store_id = $store->id;
- $order->league_price = $this->pay_price;
- $order->send_price = $this->send_price;
- $order->order_no = OrderNo::getOrderNo(OrderNo::LEAGUE_PRICE);
- $order->is_pay = 0;
- $order->pay_type = $this->pay_type;
- $order->is_delete = 0;
- $order->created_at = time();
- // var_dump($this);die;
- if ($order->save()) {
- $this->order = $order;
- $body = "充值联盟券";
- if ($this->pay_type == 1) {
- // $result = WechatAlliancePay::orderUnify($this->order,$orderType, $body, 0, false, 0);
- $result = WechatBusinessPay::orderUnify($this->order, $orderType, $body, 0, false, 0);
- if (isset($result['code']) && $result['code'] == 1) {
- return $result;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => (object)$result['data'],
- 'res' => $result['res'],
- 'body' => $body,
- ];
- }
- $goods_names = $body;
- $res = Alipay::mini($this->order, $goods_names, $this->user, '', '', 0, 0);
- if ($res['code'] != 0) {
- return $res;
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res['data'],
- 'res' => $res['data'],
- 'body' => $body,
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- }
- //商户充值
- public function storeSubmitRecharge(){
- $order = $this->order;
- $store_id = $order->store_id;
- $item = \app\models\StoreCloud::findOne(['store_id' => $store_id, 'is_delete' => 0, 'is_enable' => 1]);
- // $storeCloud = get_saas_purchase_store_cloud();
- if (!$item) {
- return [
- 'code' => 11,
- 'msg' => '商户未找到',
- ];
- }
- $form = new PlatformForm();
- $form->attributes = [
- 'id' => $item->cloud_store_id,
- 'price' => $order->pay_price,
- ];
- $res = $form->storeSubmitRecharge();
- \Yii::error([__METHOD__, 'storeSubmitRecharge', $res, $this->order, $item]);
- return $res;
- }
- }
|