| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\models;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%integral_appreciation_user_integral_log}}".
- *
- * @property integer $id
- * @property integer $integral_user_id
- * @property float $amount
- * @property integer $order_id
- * @property integer $order_type
- * @property integer $type
- * @property integer $source_type
- * @property string $desc
- * @property string $created_at
- * @property string $updated_at
- */
- class IntegralAppreciationUserIntegralLog extends \yii\db\ActiveRecord
- {
- /**
- * 收支类型:0=收入;
- */
- const TYPE_INCOME = 0;
- /**
- * 收支类型:1=支出;
- */
- const TYPE_EXPEND = 1;
- /**
- * 订单类型:0=商品订单;
- */
- const ORDER_TYPE_OR = 0;
- /**
- * 订单类型:1=拼团订单;
- */
- const ORDER_TYPE_PT = 1;
- /**
- * 来源类型:0=购买商品;
- */
- const SOURCE_TYPE_BUY_GOODS = 0;
- /**
- * 来源类型:1=账户提现;
- */
- const SOURCE_TYPE_WITHDRAW = 1;
- /**
- * 来源类型:2=转赠收入;
- */
- const SOURCE_TYPE_TRANSFER_INCOME = 2;
- /**
- * 来源类型:3=转赠支出;
- */
- const SOURCE_TYPE_TRANSFER_EXPEND = 3;
- /**
- * 来源类型:4=账户提现失败退回;
- */
- const SOURCE_TYPE_WITHDRAW_FAIL = 4;
- /**
- * 来源类型:5=购买商品订单取消退回;
- */
- const SOURCE_TYPE_ORDER_CANCEL = 5;
- /**
- * 来源类型:6=购买商品铸造积分;
- */
- const SOURCE_TYPE_CAST_INTEGRAL = 6;
- public static $source_type_desc = [
- self::SOURCE_TYPE_BUY_GOODS => '购买商品',
- self::SOURCE_TYPE_WITHDRAW => '账户提现',
- self::SOURCE_TYPE_TRANSFER_INCOME => '转赠收入',
- self::SOURCE_TYPE_TRANSFER_EXPEND => '转赠支出',
- self::SOURCE_TYPE_WITHDRAW_FAIL => '账户提现失败退回',
- self::SOURCE_TYPE_ORDER_CANCEL => '订单取消退回',
- self::SOURCE_TYPE_CAST_INTEGRAL => '购买商品铸造获取积分'
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%integral_appreciation_user_integral_log}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class
- ]
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['id', 'integral_user_id', 'type', 'source_type', 'order_id', 'order_type'], 'integer'],
- [['amount', 'created_at', 'updated_at'], 'number'],
- [['desc'], 'string']
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'integral_user_id' => '增值积分系统用户ID',
- 'amount' => '增值积分数量',
- 'order_id' => '订单号',
- 'order_type' => '订单类型:0普通订单;1=拼团订单',
- 'type' => '收支类型:0=收入;1=支出;',
- 'source_type' => '来源类型:0=购买商品;1=账户提现;2=转赠收入;3=转赠支出;4=账户提现失败退回;5=订单取消退回',
- 'desc' => '描述',
- 'created_at' => '',
- 'updated_at' => ''
- ];
- }
- public static function saveIntegralLog($user_id, $user_integral_num, $type = self::TYPE_INCOME, $source_type = self::SOURCE_TYPE_BUY_GOODS, $desc = '', $order_id = 0, $order_type = 0) {
- $user = IntegralAppreciationUser::findOne($user_id);
- if (!$user) {
- return [
- 'code' => 1,
- 'msg' => '用户不存在'
- ];
- }
- $integral_log = new IntegralAppreciationUserIntegralLog();
- $integral_log->integral_user_id = $user_id;
- $integral_log->amount = $user_integral_num;
- $integral_log->type = $type;
- $integral_log->order_id = $order_id;
- $integral_log->order_type = $order_type;
- $integral_log->source_type = $source_type;
- $integral_log->desc = $desc;
- if (!$integral_log->save()) {
- return [
- 'code' => 1,
- 'msg' => json_encode($integral_log->errors, JSON_UNESCAPED_UNICODE)
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- }
- }
|