AchievementFirstOrder.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_first_order".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $user_id
  12. * @property int $order_id 订单id
  13. * @property int $order_detail_id 订单详情id
  14. * @property int $goods_id 商品id
  15. * @property int $created_at
  16. * @property int $updated_at
  17. * @property int $status 状态[-1:删除;0:禁用;1启用]
  18. */
  19. class AchievementFirstOrder extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_achievement_first_order}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'user_id','order_id','goods_id', 'order_detail_id', 'created_at', 'updated_at', 'status'], 'integer'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => 'Mall ID',
  45. 'user_id' => 'User ID',
  46. 'order_id' => '订单id',
  47. 'order_detail_id' => '订单详情id',
  48. 'goods_id' => '商品id',
  49. 'created_at' => 'Created At',
  50. 'updated_at' => 'Updated At',
  51. 'status' => '状态[-1:删除;0:禁用;1启用]',
  52. ];
  53. }
  54. public static function setData(array $params)
  55. {
  56. try {
  57. if (!empty($params['id'])) {
  58. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  59. if (empty($model)) throw new \Exception('服务不存在或已删除');
  60. } else {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. }
  64. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  65. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  66. return $model;
  67. } catch (\Exception $e) {
  68. self::$static_error = $e->getMessage();
  69. return false;
  70. }
  71. }
  72. }