OrderCommentsTemplates.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace common\models\order;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use PHPUnit\Util\Exception;
  6. use Yii;
  7. use yii\helpers\Json;
  8. /**
  9. * This is the model class for table "qimall_order_comments_templates".
  10. *
  11. *
  12. * @property int $id
  13. * @property int $mall_id
  14. * @property int $mch_id
  15. * @property int $type 模板类型:1.好评|2.中评|3.差评
  16. * @property string $title 标题
  17. * @property string $content 内容
  18. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at 创建时间
  20. * @property int $updated_at 修改时间
  21. */
  22. class OrderCommentsTemplates extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%order_comments_templates}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id'], 'required'],
  38. [['mall_id', 'mch_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['title'], 'string', 'max' => 65],
  40. [['content'], 'string', 'max' => 255],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'mch_id' => 'Mch ID',
  52. 'type' => '模板类型:1.好评|2.中评|3.差评',
  53. 'title' => '标题',
  54. 'content' => '内容',
  55. 'status' => '状态[-1:删除;0:禁用;1启用]',
  56. 'created_at' => '创建时间',
  57. 'updated_at' => '修改时间',
  58. ];
  59. }
  60. /**
  61. * 保存数据
  62. * @Author: hua
  63. * @DateTime: 2021/10/7 17:30
  64. * @Copyright: copyright (c) 2021 广东七件事集团
  65. * @param array $params
  66. * @return bool|OrderCommentsTemplates
  67. * @throws \yii\db\Exception
  68. */
  69. public static function setData(array $params)
  70. {
  71. try {
  72. if (!empty($params['id'])) {
  73. $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  74. if (empty($model)) throw new Exception('服务不存在或已删除');
  75. } else {
  76. $model = new self();
  77. $model->loadDefaultValues();
  78. }
  79. if(isset($params['pic_url'])) $params['pic_url'] = Json::encode($params['pic_url']);
  80. if(!empty($params['virtual_time'])) $params['virtual_time'] = strtotime($params['virtual_time']);
  81. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  82. return $model;
  83. } catch (Exception $e) {
  84. self::$static_error = $e->getMessage();
  85. return false;
  86. }
  87. }
  88. }