| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\modules\admin\models\HuifuForm;
- use app\utils\OrderNo;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%alliance_coupon_settle}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property string $price
- * @property string $settle_no
- * @property integer $settle_type
- * @property integer $is_settle
- * @property integer $unusually_condition
- * @property string $unusually_msg
- * @property integer $is_delete
- * @property string $settled_at
- * @property string $created_at
- * @property string $updated_at
- */
- class AllianceCouponSettle extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%alliance_coupon_settle}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['settle_type', 'store_id', 'unusually_condition', 'is_settle', 'is_delete'], 'integer'],
- [['price'], 'number'],
- [['updated_at', 'created_at', 'settled_at', 'settle_no', 'unusually_msg'], 'string'],
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- if ($this->isNewRecord) {
- $this->created_at = date('Y-m-d H:i:s');
- } else {
- $this->updated_at = date('Y-m-d H:i:s');
- }
- return true;
- }
- return false;
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- ];
- }
- public static function addAllianceCouponSettleLog($order, $order_type)
- {
- if (!in_array($order_type, [1, 2])) return false;
- $store = Store::findOne($order->store_id);
- if ($order->take_price <= 0 || $store->small_model_proportion >= 100) return false;
- $settle_type = Option::get('alliance_coupon_settle_type', $order->store_id, 'store', 3)['value'];
- $settle = null;
- if ($settle_type != 0 && $settle_type != 1) {
- $settle = AllianceCouponSettle::find()->where(['store_id' => $order->store_id, 'is_settle' => 0, 'is_delete' => 0])->one();
- }
- if (!$settle) {
- $settle = new AllianceCouponSettle();
- $settle->store_id = $order->store_id;
- $settle->settle_no = OrderNo::getOrderNo(OrderNo::ALLIANCE_COUPON_SETTLE);
- $settle->price = 0;
- }
- $price = $order->take_price * ($store->small_model_proportion / 100);
- $add_price = $order->take_price - $price;
- $settle->price += $add_price;
- if (!$settle->save()) {
- ActionLog::addLog(1, 'addAllianceCouponSettleLog', $settle->getErrorSummary(false)[0]);
- }
- $detail = new AllianceCouponSettleDetail();
- $detail->order_id = $order->id;
- $detail->store_id = $order->store_id;
- $detail->price = $add_price;
- $detail->take_price = $order->take_price;
- $detail->rl_rate = $store->small_model_proportion;
- $detail->order_type = $order_type;
- $detail->settle_id = $settle->id;
- if (!$detail->save()) {
- ActionLog::addLog(1, 'addAllianceCouponSettleLog', $detail->getErrorSummary(false)[0]);
- }
- if ($settle_type == 1 && $detail->take_price > 0) {
- $form = new HuifuForm();
- $res = $form->actionHuifuyunpan($settle->id);
- switch ($res['code']) {
- case 0:
- $settle->settled_at = date('Y-m-d H:i:s');
- $settle->is_settle = 1;
- break;
- case 1:
- $settle->unusually_condition = 1;
- $settle->unusually_msg = $res['msg'];
- break;
- case 3:
- $settle->unusually_condition = 1;
- $settle->settle_type = 3;
- $settle->unusually_msg = $res['msg'];
- break;
- default:
- $settle->unusually_condition = 1;
- $settle->settle_type = 3;
- $settle->unusually_msg = '打款状态不明,请检查是否打款成功';
- break;
- }
- if (!$settle->save()) {
- ActionLog::addLog(1, 'addAllianceCouponSettleLog', $settle->getErrorSummary(false)[0]);
- }
- }
- return true;
- }
- }
|