| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace addons\SecondaryCard\common\models;
- use common\enums\StatusEnum;
- use common\helpers\StringHelper;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_secondary_card_order".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 会员id
- * @property int $secondary_card_id 次卡id
- * @property int $use_type 使用范围:0:全部店铺;1:指定店铺
- * @property string $order_no 次卡号
- * @property string $clerk_code 核销码
- * @property int|null $order_status 状态:0:待核销;1:已失效;2:已过期;3:已退款;4:已停卡
- * @property int $open_time 开卡时间:需要支付时,支付时间
- * @property int $open_type 开卡方式:1:下单购买;2:兑换码兑换
- * @property float $pay_money 购卡实收金额
- * @property int $pay_type 支付方式:1=微信支付,2=货到付款,3=余额支付,4=支付宝支付,5=银联支付,6=汇聚聚合支付,7=汇聚快捷支付
- * @property int $start_time 有效期开始时间
- * @property int $expire_time 有效期结束时间,过期时间
- * @property int $refund_source 退款来源:1:会员申请;2:过期,后台操作退款
- * @property float $refund_money 退款金额
- * @property int $refund_time 退款时间
- * @property int $verifiable_times 可核销次数
- * @property string $code 兑换码
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at
- * @property int $trade_id
- * @property int $create_source_type 创建来源类型:0:平台;1:门店
- * @property int $create_source_id 创建来源id
- */
- class SecondaryCardOrder extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_secondary_card_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id'], 'required'],
- [['mall_id', 'user_id', 'use_type', 'secondary_card_id', 'order_status', 'open_time', 'open_type', 'pay_type',
- 'start_time', 'expire_time', 'refund_source', 'refund_time', 'verifiable_times', 'status', 'created_at', 'updated_at','trade_id',
- 'create_source_type','create_source_id'], 'integer'],
- [['pay_money', 'refund_money'], 'number'],
- [['order_no', 'code'], 'string', 'max' => 255],
- [['clerk_code'], 'string', 'max' => 12],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => '会员id',
- 'secondary_card_id' => '次卡id',
- 'use_type' => '使用范围:0:全部店铺;1:指定店铺',
- 'order_no' => '次卡号',
- 'clerk_code' => '核销码',
- 'order_status' => '状态:0:待核销;1:已失效;2:已过期;3:已退款;4:已停卡',
- 'open_time' => '开卡时间:需要支付时,支付时间',
- 'open_type' => '开卡方式:1:下单购买;2:兑换码兑换',
- 'pay_money' => '购卡实收金额',
- 'pay_type' => '支付方式:1=微信支付,2=货到付款,3=余额支付,4=支付宝支付,5=银联支付,6=汇聚聚合支付,7=汇聚快捷支付',
- 'start_time' => '有效期开始时间',
- 'expire_time' => '有效期结束时间,过期时间',
- 'refund_source' => '退款来源:1:会员申请;2:过期,后台操作退款',
- 'refund_money' => '退款金额',
- 'refund_time' => '退款时间',
- 'verifiable_times' => '可核销次数',
- 'code' => '兑换码',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => 'Updated At',
- 'trade_id' => 'trade_id',
- 'create_source_type' => '创建来源类型:0:平台;1:门店',
- 'create_source_id' => '创建来源id',
- ];
- }
- public static function getExportFields()
- {
- return [
- 'order_no' => '卡号',
- 'nickname' => '开卡用户',
- 'order_status' => '次卡状态',
- 'open_time' => '开卡时间',
- 'open_type' => '开卡方式',
- 'pay_money' => '购卡实收金额',
- 'expire_time' => '到期时间',
- 'refund_money' => '退款金额',
- 'refund_time' => '退款时间',
- ];
- }
- public function getSecondaryCard()
- {
- return $this->hasOne(SecondaryCard::class, ['id' => 'secondary_card_id']);
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- *
- * @Author:hua
- * @Date:2024-03-08 14:35
- * @Copyright:copyright(c)2024 广东七件事集团
- * @param int $len
- * @return false|string
- */
- public static function getOrderNo()
- {
- while (true) {
- $order_no = StringHelper::generateRandCode(10);
- $rand = mt_rand(10000, 99999);
- $order_no = $rand . $order_no;
- $res = SecondaryCardOrder::findOne(['order_no' => $order_no, 'status' => StatusEnum::ENABLED]);
- if (empty($res)) {
- break;
- }
- }
- return $order_no;
- }
- }
|