AchievementUser.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace addons\Achievement\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_achievement_user".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城id
  11. * @property int|null $user_id 用户id
  12. * @property float $total_commission 累计佣金
  13. * @property int $created_at
  14. * @property int $updated_at
  15. * @property int $status 状态[-1:删除;0:禁用;1启用]
  16. */
  17. class AchievementUser extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_addons_achievement_user';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'created_at', 'updated_at', 'status', 'is_manual'], 'integer'],
  33. [['total_commission'], '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. 'total_commission' => '累计佣金',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. 'status' => '状态[-1:删除;0:禁用;1启用]',
  49. 'integer' => '是否手动添加[1:是 0:否]',
  50. ];
  51. }
  52. public static function setData(array $params)
  53. {
  54. try {
  55. if (!empty($params['id'])) {
  56. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  57. if (empty($model)) throw new \Exception('服务不存在或已删除');
  58. } else {
  59. $model = new self();
  60. $model->loadDefaultValues();
  61. }
  62. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  63. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  64. if($model->status==StatusEnum::DELETE){
  65. AchievementFirstOrder::updateAll(['status'=>StatusEnum::DELETE,'updated_at'=>time()],['mall_id'=>$model->mall_id,'user_id'=>$model->user_id]);
  66. }
  67. return $model;
  68. } catch (\Exception $e) {
  69. self::$static_error = $e->getMessage();
  70. return false;
  71. }
  72. }
  73. }