ClockinRewardLog.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace addons\Clockin\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "{{%addons_clockin_reward_log}}".
  7. *
  8. * @property int $id
  9. * @property int|null $mall_id 商城ID
  10. * @property int|null $user_id 会员ID
  11. * @property int|null $apply_id 关联clockin_apply.id
  12. * @property float|null $reward 奖励
  13. * @property int $status 状态[0禁用 1启用 -1删除]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. */
  17. class ClockinRewardLog extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_clockin_reward_log}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'apply_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['reward'], 'number'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城ID',
  44. 'user_id' => '会员ID',
  45. 'apply_id' => '关联clockin_apply.id',
  46. 'reward' => '奖励',
  47. 'status' => '状态[0禁用 1启用 -1删除]',
  48. 'created_at' => '创建时间',
  49. 'updated_at' => '修改时间',
  50. ];
  51. }
  52. /**
  53. * 添加记录
  54. * @Author: lun
  55. * @DateTime: 2023/7/26 0026 15:17
  56. * @Copyright: copyright (c) 2021 广东七件事集团
  57. * @param $apply
  58. * @param $reward_score
  59. * @return bool
  60. * @throws Exception
  61. */
  62. public static function addLog($apply, $reward_score)
  63. {
  64. $model = new self();
  65. $model->mall_id = $apply['mall_id'];
  66. $model->user_id = $apply['user_id'];
  67. $model->apply_id = $apply['id'];
  68. $model->reward = $reward_score;
  69. if (!$model->save()) throw new Exception($model->getErrorMessage());
  70. return true;
  71. }
  72. }