IntegralAppreciationUserIntegralLog.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. /**
  11. * This is the model class for table "{{%integral_appreciation_user_integral_log}}".
  12. *
  13. * @property integer $id
  14. * @property integer $integral_user_id
  15. * @property float $amount
  16. * @property integer $order_id
  17. * @property integer $order_type
  18. * @property integer $type
  19. * @property integer $source_type
  20. * @property string $desc
  21. * @property string $created_at
  22. * @property string $updated_at
  23. */
  24. class IntegralAppreciationUserIntegralLog extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * 收支类型:0=收入;
  28. */
  29. const TYPE_INCOME = 0;
  30. /**
  31. * 收支类型:1=支出;
  32. */
  33. const TYPE_EXPEND = 1;
  34. /**
  35. * 订单类型:0=商品订单;
  36. */
  37. const ORDER_TYPE_OR = 0;
  38. /**
  39. * 订单类型:1=拼团订单;
  40. */
  41. const ORDER_TYPE_PT = 1;
  42. /**
  43. * 来源类型:0=购买商品;
  44. */
  45. const SOURCE_TYPE_BUY_GOODS = 0;
  46. /**
  47. * 来源类型:1=账户提现;
  48. */
  49. const SOURCE_TYPE_WITHDRAW = 1;
  50. /**
  51. * 来源类型:2=转赠收入;
  52. */
  53. const SOURCE_TYPE_TRANSFER_INCOME = 2;
  54. /**
  55. * 来源类型:3=转赠支出;
  56. */
  57. const SOURCE_TYPE_TRANSFER_EXPEND = 3;
  58. /**
  59. * 来源类型:4=账户提现失败退回;
  60. */
  61. const SOURCE_TYPE_WITHDRAW_FAIL = 4;
  62. /**
  63. * 来源类型:5=购买商品订单取消退回;
  64. */
  65. const SOURCE_TYPE_ORDER_CANCEL = 5;
  66. /**
  67. * 来源类型:6=购买商品铸造积分;
  68. */
  69. const SOURCE_TYPE_CAST_INTEGRAL = 6;
  70. public static $source_type_desc = [
  71. self::SOURCE_TYPE_BUY_GOODS => '购买商品',
  72. self::SOURCE_TYPE_WITHDRAW => '账户提现',
  73. self::SOURCE_TYPE_TRANSFER_INCOME => '转赠收入',
  74. self::SOURCE_TYPE_TRANSFER_EXPEND => '转赠支出',
  75. self::SOURCE_TYPE_WITHDRAW_FAIL => '账户提现失败退回',
  76. self::SOURCE_TYPE_ORDER_CANCEL => '订单取消退回',
  77. self::SOURCE_TYPE_CAST_INTEGRAL => '购买商品铸造获取积分'
  78. ];
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public static function tableName()
  83. {
  84. return '{{%integral_appreciation_user_integral_log}}';
  85. }
  86. public function behaviors()
  87. {
  88. return [
  89. [
  90. 'class' => TimestampBehavior::class
  91. ]
  92. ];
  93. }
  94. /**
  95. * {@inheritdoc}
  96. */
  97. public function rules()
  98. {
  99. return [
  100. [['id', 'integral_user_id', 'type', 'source_type', 'order_id', 'order_type'], 'integer'],
  101. [['amount', 'created_at', 'updated_at'], 'number'],
  102. [['desc'], 'string']
  103. ];
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function attributeLabels()
  109. {
  110. return [
  111. 'id' => '',
  112. 'integral_user_id' => '增值积分系统用户ID',
  113. 'amount' => '增值积分数量',
  114. 'order_id' => '订单号',
  115. 'order_type' => '订单类型:0普通订单;1=拼团订单',
  116. 'type' => '收支类型:0=收入;1=支出;',
  117. 'source_type' => '来源类型:0=购买商品;1=账户提现;2=转赠收入;3=转赠支出;4=账户提现失败退回;5=订单取消退回',
  118. 'desc' => '描述',
  119. 'created_at' => '',
  120. 'updated_at' => ''
  121. ];
  122. }
  123. 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) {
  124. $user = IntegralAppreciationUser::findOne($user_id);
  125. if (!$user) {
  126. return [
  127. 'code' => 1,
  128. 'msg' => '用户不存在'
  129. ];
  130. }
  131. $integral_log = new IntegralAppreciationUserIntegralLog();
  132. $integral_log->integral_user_id = $user_id;
  133. $integral_log->amount = $user_integral_num;
  134. $integral_log->type = $type;
  135. $integral_log->order_id = $order_id;
  136. $integral_log->order_type = $order_type;
  137. $integral_log->source_type = $source_type;
  138. $integral_log->desc = $desc;
  139. if (!$integral_log->save()) {
  140. return [
  141. 'code' => 1,
  142. 'msg' => json_encode($integral_log->errors, JSON_UNESCAPED_UNICODE)
  143. ];
  144. }
  145. return [
  146. 'code' => 0,
  147. 'msg' => '操作成功'
  148. ];
  149. }
  150. }