StoreReserveTechnicianScheduling.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Store\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_store_reserve_technician_scheduling".
  8. *
  9. * @property int $id id
  10. * @property int $mall_id 商城id
  11. * @property int|null $user_id user_id
  12. * @property int|null $store_id 门店id
  13. * @property int|null $date_time 日期
  14. * @property int $is_all_day 是否全天(0:不是,1:是)
  15. * @property int $status 状态(-1:删除,0:禁用,1:启用)
  16. * @property int|null $created_at 创建时间
  17. * @property int|null $updated_at 修改时间
  18. */
  19. class StoreReserveTechnicianScheduling extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_store_reserve_technician_scheduling}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id'], 'required'],
  35. [['mall_id', 'user_id', 'store_id', 'date_time', 'is_all_day', 'status', 'created_at', 'updated_at'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => 'Mall ID',
  46. 'user_id' => 'User ID',
  47. 'store_id' => 'store_id',
  48. 'date_time' => 'Date Time',
  49. 'is_all_day' => 'Is All Day',
  50. 'status' => 'Status',
  51. 'created_at' => 'Created At',
  52. 'updated_at' => 'Updated At',
  53. ];
  54. }
  55. public function getSchedulingTime()
  56. {
  57. return $this->hasMany(StoreReserveTechnicianSchedulingTime::class, ['sid' => 'id'])->andWhere(['status' => [StatusEnum::ENABLED]])->select('id,start_time,end_time,sid');
  58. }
  59. public static function setData($params)
  60. {
  61. try {
  62. if (!empty($params['id'])) {
  63. $model = self::find()->where(['id' => $params['id']])->one();
  64. if (empty($model)) throw new \Exception('数据不存在');
  65. } else {
  66. $model = new self();
  67. }
  68. $model->loadDefaultValues();
  69. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  70. return $model;
  71. } catch (\Exception $e) {
  72. self::$static_error = $e->getMessage();
  73. return false;
  74. }
  75. }
  76. public static function getDataOne($params, $select = "*", $orderBy = 'id desc')
  77. {
  78. return self::find()->where($params)->select($select)->orderBy($orderBy)->asArray()->one();
  79. }
  80. public static function getDataAll($params, $select = "*", $orderBy = 'id desc')
  81. {
  82. return self::find()->where($params)->select($select)->orderBy($orderBy)->asArray()->all();
  83. }
  84. }