| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace addons\HiGo\common\models;
- use addons\HiGo\common\enums\HiGoEnum;
- use common\enums\StatusEnum;
- use Yii;
- use Exception;
- /**
- * This is the model class for table "{{%recharge_orders}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $order_no
- * @property int $user_id
- * @property int $price_setting_method
- * @property float $pay_price 充值金额
- * @property float $hi_bei 嗨贝数额
- * @property int $pay_type 支付方式 1.线上支付
- * @property int $is_pay 是否支付 0--未支付 1--支付
- * @property int $pay_at
- * @property int $status
- * @property int $created_at 创建时间
- * @property int $deleted_at 删除时间
- * @property int $updated_at 修改时间
- * @property int $give_score 赠送积分
- */
- class HigoRechargeOrders extends \common\models\base\BaseActiveRecord
- {
- /**
- * 支付方式: 线上支付
- */
- const PAY_TYPE_ON_LINE = 1;
- //充值方式:
- const RECHARGE_TYPE_USER = 0;
- const RECHARGE_TYPE_ADMIN = 1;
- const IS_PAY = 1;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_higo_recharge_orders}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'pay_price', 'pay_type'], 'required'],
- [['mall_id', 'user_id', 'pay_type', 'is_pay', 'pay_at', 'status', 'created_at', 'deleted_at', 'updated_at', 'price_setting_method'], 'integer'],
- [['pay_price', 'hi_bei'], 'number'],
- [['order_no'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'order_no' => 'Order No',
- 'user_id' => 'User ID',
- 'pay_price' => 'Pay Price',
- 'hi_bei' => 'Hi Bei',
- 'price_setting_method' => 'Price Setting Method',
- 'pay_type' => 'Pay Type',
- 'is_pay' => 'Is Pay',
- 'pay_at' => 'Pay At',
- 'is_delete' => 'Is Delete',
- 'created_at' => 'Created At',
- 'deleted_at' => 'Deleted At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function createOrder($params)
- {
- try {
- $recharge = Yii::$app->services->setting->addons->get($params['mall_id'], HiGoEnum::ADDONS_NAME, 'recharge');
- $hi_bei = 0;
- if ($params['price_setting_method'] == 1) {
- $hi_bei = bcmul($params['pay_price'], bcdiv($recharge['price_setting_ratio'], 100, 10), 10);
- }
- if ($params['price_setting_method'] == 0) {
- $price_ladder = isset($recharge['price_ladder']) ? json_decode($recharge['price_ladder'], true) : [];
- foreach ($price_ladder as $item) {
- if ($item['uuid'] == $params['uuid']) {
- $hi_bei = $item['give'];
- break;
- }
- }
- }
- if ($hi_bei <= 0) {
- throw new Exception('系统充值设置异常,请稍后再试');
- }
- if ($hi_bei != $params['hi_bei']) {
- throw new Exception('系统充值设置异常,请联系系统管理员处理');
- }
- $wallet_text = HiGoEnum::getHigoWalletText($params['mall_id']);
- $hi_bei_name = $wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI];
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->pay_price = $params['pay_price'];
- $model->hi_bei = $params['hi_bei'];
- $model->order_no = HiGoEnum::generateOrderNo('HIRE');
- $model->user_id = $params['user_id'];
- $model->price_setting_method = $params['price_setting_method'];
- $model->status = StatusEnum::ENABLED;
- $model->pay_type = self::PAY_TYPE_ON_LINE;
- $model->save();
- $order_trade_info[] = [
- 'order_no' => $model->order_no,
- 'amount' => $model->pay_price,
- 'title' => '充值' . $hi_bei_name,
- 'notify_class' => 'addons\HiGo\common\logic\notify\RechargeNotify',
- 'order_type' => HiGoEnum::ADDONS_NAME . '_Recharge'
- ];
- //生成支付流水
- return \Yii::$app->services->pay->createTrade($params['mall_id'], $params['user_id'], $order_trade_info);
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function check($params): bool
- {
- $order_no_arr = $params['order_no_arr'];
- $payment_order_list = $params['payment_order_list'];
- $counts = self::find()->where(['order_no' => $order_no_arr, 'is_pay' => 0])->count();
- if ($counts != count($payment_order_list)) {
- self::$static_error = '充值订单不一致';
- return false;
- }
- return true;
- }
- }
|