SalesCompany.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\SalesCompany\common\models;
  3. use Yii;
  4. use common\models\base\BaseActiveRecord;
  5. use common\enums\StatusEnum;
  6. /**
  7. * This is the model class for table "{{%addons_sales_company}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property string $name 销售公司名称
  13. * @property int $is_enable 是否启用 0 否 1 是
  14. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 修改时间
  17. */
  18. class SalesCompany extends BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_sales_company}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'user_id', 'is_enable', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['name'], 'string', 'max' => 100],
  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. 'name' => 'Name',
  47. 'is_enable' => 'Is Enable',
  48. 'status' => 'Status',
  49. 'created_at' => 'Created At',
  50. 'updated_at' => 'Updated At',
  51. ];
  52. }
  53. public static function setData(array $params)
  54. {
  55. try {
  56. if (!empty($params['id'])) {
  57. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  58. if (empty($model)) throw new \Exception('销售公司不存在或已删除');
  59. } else {
  60. $model = new self();
  61. $model->loadDefaultValues();
  62. }
  63. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  64. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  65. return $model;
  66. } catch (\Exception $e) {
  67. self::$static_error = $e->getMessage();
  68. return false;
  69. }
  70. }
  71. }