SecondaryCardUseLog.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace addons\SecondaryCard\common\models;
  3. use addons\Clerk\common\models\ClerkUser;
  4. use addons\Store\common\models\Store;
  5. use common\enums\StatusEnum;
  6. use common\models\base\BaseActiveRecord;
  7. use common\models\user\User;
  8. use Yii;
  9. /**
  10. * This is the model class for table "qimall_addons_secondary_card_reservation_service".
  11. *
  12. * @property int $id ID
  13. * @property int $mall_id 商城ID
  14. * @property int $user_id 用户ID
  15. * @property int $order_id 开卡记录id
  16. * @property int $secondary_card_id 次卡ID
  17. * @property string $order_no 次卡号
  18. * @property int $clerk_nums 单次核销数
  19. * @property int $type 类型:1:o2o门店;
  20. * @property int $store_id 核销门店id;
  21. * @property int $status 状态0禁用,-1删除,1正常
  22. * @property int $open_time 开卡时间
  23. * @property int $created_at 创建时间
  24. * @property int $updated_at 更新时间
  25. * @property float $clerk_money 订单核销金额
  26. * @property float $service_income 技师服务收入
  27. * @property int $reservation_service_order_id 预约服务插件,服务订单id
  28. * @property int $clerk_user_id 预约服务插件,技师user_id;
  29. * @property int $clerk_type 核销类型:1:门店核销;2:技师核销;
  30. * @property int $clerk_log_id 公共核销记录id
  31. */
  32. class SecondaryCardUseLog extends BaseActiveRecord
  33. {
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public static function tableName()
  38. {
  39. return '{{%addons_secondary_card_use_log}}';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['mall_id'], 'required'],
  48. [['mall_id', 'user_id', 'order_id', 'secondary_card_id', 'clerk_nums', 'type', 'store_id', 'reservation_service_order_id', 'clerk_user_id', 'clerk_type',
  49. 'status', 'created_at', 'updated_at', 'open_time','clerk_log_id'], 'integer'],
  50. [['clerk_money', 'service_income'], 'number'],
  51. [['order_no'], 'string'],
  52. ];
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'mall_id' => '商城ID',
  62. 'user_id' => '用户ID',
  63. 'order_id' => 'order_id',
  64. 'order_no' => 'order_no',
  65. 'clerk_nums' => 'clerk_nums',
  66. 'type' => 'type',
  67. 'store_id' => 'store_id',
  68. 'clerk_money' => 'clerk_money',
  69. 'service_income' => 'service_income',
  70. 'clerk_type' => 'clerk_type',
  71. 'reservation_service_order_id' => 'reservation_service_order_id',
  72. 'clerk_user_id' => 'clerk_user_id',
  73. 'secondary_card_id' => '绑定的次卡ID',
  74. 'status' => '状态0禁用,-1删除,1正常',
  75. 'created_at' => '创建时间',
  76. 'updated_at' => '更新时间',
  77. 'open_time' => '开卡时间',
  78. 'clerk_log_id' => '公共核销记录id',
  79. ];
  80. }
  81. public function getSecondaryCard()
  82. {
  83. return $this->hasOne(SecondaryCard::class, ['id' => 'secondary_card_id']);
  84. }
  85. public function getSecondaryCardOrder()
  86. {
  87. return $this->hasOne(SecondaryCardOrder::class, ['order_no' => 'order_no']);
  88. }
  89. public function getClerkUser()
  90. {
  91. return $this->hasOne(User::class, ['id' => 'clerk_user_id']);
  92. }
  93. public function getUser()
  94. {
  95. return $this->hasOne(User::class, ['id' => 'user_id']);
  96. }
  97. public static function getExportFields()
  98. {
  99. return [
  100. 'order_no' => '卡号',
  101. 'secondary_card_name' => '次卡名称',
  102. 'nickname' => '开卡用户',
  103. 'open_time' => '开卡时间',
  104. 'clerk_nums' => '单次核销次数',
  105. 'store_name' => '核销门店',
  106. 'clerk_nickname' => '核销人',
  107. 'created_at' => '核销时间',
  108. ];
  109. }
  110. public static function setData(array $params)
  111. {
  112. try {
  113. if (!empty($params['id'])) {
  114. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  115. if (empty($model)) throw new \Exception('服务不存在或已删除');
  116. } else {
  117. $model = new self();
  118. $model->loadDefaultValues();
  119. }
  120. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  121. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  122. return $model;
  123. } catch (\Exception $e) {
  124. self::$static_error = $e->getMessage();
  125. return false;
  126. }
  127. }
  128. }