DepositPresaleCate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace addons\DepositPresale\common\models;
  3. use addons\DepositPresale\common\enums\DepositPresaleEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\base\BaseActiveRecord;
  6. use common\models\goods\Goods;
  7. use Yii;
  8. /**
  9. * This is the model class for table "qimall_addons_deposit_presale_cate".
  10. *
  11. * @property int $id
  12. * @property int $mall_id 商城id
  13. * @property string $name 名称
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at
  16. * @property int $updated_at
  17. */
  18. class DepositPresaleCate extends BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_deposit_presale_cate}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'name'], 'required'],
  34. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  35. [['name'], 'string', 'max' => 20],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => '商城id',
  46. 'name' => '名称',
  47. 'status' => '状态[-1:删除;0:禁用;1启用]',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. public static function setData(array $params)
  53. {
  54. try {
  55. if (!empty($params['id'])) {
  56. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  57. if (empty($model)) throw new \Exception('服务不存在或者已删除');
  58. } else {
  59. $model = new self();
  60. }
  61. $model->loadDefaultValues();
  62. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  63. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  64. return $model;
  65. } catch (\Exception $e) {
  66. self::$static_error = $e->getMessage();
  67. return false;
  68. }
  69. }
  70. public static function getCateListByDiy($mall_id, $post)
  71. {
  72. $where[] = ['mall_id' => $mall_id];
  73. $where[] = ['status' => StatusEnum::ENABLED];
  74. if (!empty($post['keyword'])) $where[] = ['like', 'name', trim($post['keyword']) . '%', false];
  75. $params['limit'] = 10;
  76. $params['where'] = $where;
  77. $params['select'] = 'id,name,created_at';
  78. $list = self::listPage($params);
  79. $first = [
  80. 'created_at' => 0,
  81. 'id' => 0,
  82. 'is_list' => 0,
  83. 'label' => "全部",
  84. 'name' => "全部",
  85. 'pid' => 0,
  86. 'title' => "全部",
  87. 'value' => 1,
  88. ];
  89. if (!empty($list['list'])) {
  90. foreach ($list['list'] as &$item) {
  91. $item['is_list'] = 0;
  92. $item['label'] = $item['name'];
  93. $item['title'] = $item['name'];
  94. $item['value'] = $item['id'];
  95. $item['pid'] = 0;
  96. }
  97. }
  98. array_unshift($list['list'],$first);
  99. return $list;
  100. }
  101. }