ClerkUser.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\Clerk\common\models;
  3. use addons\Agent\common\enums\AgentEnum;
  4. use common\components\export\CsvTool;
  5. use common\enums\DownloadEnum;
  6. use common\enums\StatusEnum;
  7. use common\helpers\ArrayHelper;
  8. use common\models\base\BaseActiveRecord;
  9. use common\models\common\Download;
  10. use common\models\mall\MallAddons;
  11. use common\models\user\User;
  12. use common\models\user\UserPartitionRelationship;
  13. use common\models\user\UserTeamStatistics;
  14. use Exception;
  15. use Yii;
  16. class ClerkUser extends BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_clerk_user}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id','store_id', 'user_id'], 'required'],
  32. [['mall_id','store_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'store_id' => 'Store ID',
  44. 'user_id' => 'User ID',
  45. 'status' => '状态[-1:删除;0:禁用;1启用]',
  46. 'created_at' => '创建时间',
  47. 'updated_at' => '修改时间',
  48. ];
  49. }
  50. public function getUser()
  51. {
  52. return $this->hasOne(User::class, ['id' => 'user_id']);
  53. }
  54. public static function setData(array $params)
  55. {
  56. try {
  57. if (!empty($params['id'])) {
  58. $where = ['id'=> $params['id'],'mall_id' => $params['mall_id'],'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  59. $model = self::findOne($where);
  60. if (empty($model)) throw new \Exception('服务不存在或已删除');
  61. } else {
  62. $model = new self();
  63. $model->loadDefaultValues();
  64. }
  65. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  66. if (!$model->save()) throw new Exception($model->getErrorMessage());
  67. return $model;
  68. } catch (\Exception $e) {
  69. self::$static_error = $e->getMessage();
  70. return false;
  71. }
  72. }
  73. }