StoreMoneyLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /*
  3. * @Author: chaimeihan 1852293413@qq.com
  4. * @Date: 2024-08-14 17:02:45
  5. * @LastEditors: chaimeihan 1852293413@qq.com
  6. * @LastEditTime: 2024-08-14 17:38:24
  7. * @FilePath: \PHP\models\StoreMoneyLog.php
  8. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  9. */
  10. namespace app\models;
  11. use Yii;
  12. use yii\behaviors\TimestampBehavior;
  13. use yii\db\ActiveRecord;
  14. /**
  15. * This is the model class for table "{{%store_money_log}}".
  16. */
  17. class StoreMoneyLog extends \yii\db\ActiveRecord
  18. {
  19. /**
  20. * 收入类型
  21. */
  22. const LOG_TYPE_INCOME = 1;
  23. /**
  24. * 支出类型
  25. */
  26. const LOG_TYPE_EXPEND = 2;
  27. const STORE_QUOTA = 1; // 店铺总额度
  28. const STORE_BALANCE = 2; // 店铺剩余额度
  29. const STORE_WITHDRAWN_CASH = 3; // 店铺已提现额度
  30. const TYPE_STORE = 0;
  31. const TYPE_SHARE = 1; // 分销提现
  32. const TYPE_SHAREHOLDER = 2; // 股东分红提现
  33. const TYPE_SHOP = 3; // 门店提现
  34. const TYPE_TWO_ADD_ONE = 4; // 2+1提现
  35. /**
  36. * @inheritdoc
  37. */
  38. public static function tableName()
  39. {
  40. return '{{%store_money_log}}';
  41. }
  42. public function behaviors()
  43. {
  44. return [
  45. [
  46. 'class' => TimestampBehavior::class,
  47. 'attributes' => [
  48. ActiveRecord::EVENT_BEFORE_INSERT => 'created_at',
  49. ]
  50. ]
  51. ];
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. public function rules()
  57. {
  58. return [
  59. [[
  60. 'type',
  61. 'store_id',
  62. 'amount',
  63. 'desc',
  64. 'type',
  65. 'before',
  66. 'after',
  67. 'recharge_type'
  68. ], 'required'],
  69. [[
  70. 'type',
  71. 'recharge_type',
  72. ], 'integer'],
  73. [[
  74. 'type',
  75. 'amount',
  76. 'type',
  77. 'before',
  78. 'after',
  79. 'recharge_type',
  80. 'wechat_type'
  81. ], 'number'],
  82. [['desc'], 'string'],
  83. ];
  84. }
  85. /**
  86. * @inheritdoc
  87. */
  88. public function attributeLabels()
  89. {
  90. return [
  91. 'id' => 'ID',
  92. 'store_id' => '店铺id',
  93. 'recharge_type' => '类型:1=收入,2=支出',
  94. 'type' => '0系统默认 1:分销提现 2:股东分红提现 3:门店提现 4:2+1提现的时候',
  95. 'amount' => '变动数',
  96. 'desc' => '变动说明',
  97. 'before' => '变动前',
  98. 'after' => '变动后',
  99. ];
  100. }
  101. public static function saveLog($storeId, $rechargeType, $type, $amount, $desc, $before, $after, $wechat_type = -1)
  102. {
  103. $log = new static();
  104. $log->store_id = $storeId;
  105. $log->recharge_type = $rechargeType;
  106. $log->type = $type;
  107. $log->amount = $amount;
  108. $log->desc = $desc;
  109. $log->before = $before;
  110. $log->after = $after;
  111. $log->wechat_type = $wechat_type;
  112. if (!$log->save()) {
  113. return $log->getErrors();
  114. }
  115. return true;
  116. }
  117. }