SalesCompanyAgent.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace addons\SalesCompany\common\models;
  3. use Yii;
  4. use common\models\base\BaseActiveRecord;
  5. /**
  6. * This is the model class for table "{{%addons_sales_company_agent}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property int $user_id 用户ID
  11. * @property int $company_id 销售公司id
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at 创建时间
  14. * @property int $updated_at 修改时间
  15. */
  16. class SalesCompanyAgent extends BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_sales_company_agent}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'user_id', 'company_id', 'status', 'created_at', 'updated_at'], 'integer'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'mall_id' => 'Mall ID',
  42. 'user_id' => 'User ID',
  43. 'company_id' => 'Company ID',
  44. 'status' => 'Status',
  45. 'created_at' => 'Created At',
  46. 'updated_at' => 'Updated At',
  47. ];
  48. }
  49. public static function setData(array $params)
  50. {
  51. try {
  52. if (!empty($params['id'])) {
  53. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  54. if (empty($model)) throw new \Exception('数据不存在或已删除');
  55. } else {
  56. $model = new self();
  57. $model->loadDefaultValues();
  58. }
  59. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  60. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  61. return $model;
  62. } catch (\Exception $e) {
  63. self::$static_error = $e->getMessage();
  64. return false;
  65. }
  66. }
  67. }