| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace common\models\order;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_order_comments_templates".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property int $mch_id
- * @property int $type 模板类型:1.好评|2.中评|3.差评
- * @property string $title 标题
- * @property string $content 内容
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class OrderCommentsTemplates extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%order_comments_templates}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'mch_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title'], 'string', 'max' => 65],
- [['content'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'mch_id' => 'Mch ID',
- 'type' => '模板类型:1.好评|2.中评|3.差评',
- 'title' => '标题',
- 'content' => '内容',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- /**
- * 保存数据
- * @Author: hua
- * @DateTime: 2021/10/7 17:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return bool|OrderCommentsTemplates
- * @throws \yii\db\Exception
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if(isset($params['pic_url'])) $params['pic_url'] = Json::encode($params['pic_url']);
- if(!empty($params['virtual_time'])) $params['virtual_time'] = strtotime($params['virtual_time']);
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|