'购买商品', 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' => '操作成功' ]; } }