| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- namespace common\models\mall;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%optimize}}".
- *
- *
- * @property int $id id
- * @property int $mall_id 商城id
- * @property int $optimize_id qimall_optimize.id
- * @property string $ip IP
- * @property int $member_id 操作人id
- * @property string|null $member_name 操作人
- * @property string|null $optimize 优化建议
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at
- * @property int $updated_at
- */
- class OptimizeDetail extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%optimize_detail}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'member_id', 'member_name'], 'required'],
- [['mall_id', 'optimize_id', 'member_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['ip', 'member_name', 'optimize'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'optimize_id' => 'qimall_optimize.id',
- 'ip' => 'ip',
- 'member_id' => '操作人id',
- 'member_name' => '操作人',
- 'optimize' => '优化建议',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 新增数据
- * @Author lun
- * @DateTime 2021-09-16 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return OptimizeDetail|boolean
- */
- public static function setData(array $params)
- {
- try {
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 沟通回复
- * @param array $params
- * @return bool
- */
- public static function resubmit(array $params)
- {
- try {
- $model = Optimize::findOne(['id' => $params['optimize_id'], 'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
- if (!$model) {
- throw new \Exception('查无此优化项');
- }
- $detail = self::setData($params);
- if ($detail === false) throw new \Exception(self::getStaticError());
- $model->examine_status = 1;
- $model->save();
- // 推送到中台
- Optimize::pushDetail($detail);
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 接收回调
- * @param $params
- * @return bool
- */
- public static function receiveNotify($params)
- {
- try {
- $model = Optimize::findOne(['id' => $params['optimize_id'], 'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
- if (!$model) {
- throw new \Exception('查无此优化项');
- }
- // 生成沟通记录
- $res = self::setData($params);
- if ($res == false) throw new \Exception(self::getStaticError());
- $model->examine_status = 2;
- $model->save();
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 添加回复
- *
- * @param array $data
- * @return boolean
- */
- public static function addReply(array $data)
- {
- try {
- $model = Optimize::findOne(['id' => $data['optimize_id'], 'mall_id' => $data['mall_id']]);
- if (!$model) {
- throw new \Exception('查无此优化项');
- }
- // 生成沟通记录
- $data = array_merge($data, [
- 'member_id' => 0,
- 'member_name' => '中台回复',
- ]);
- $res = self::setData($data);
- if ($res == false) throw new \Exception(self::getStaticError());
- $model->examine_status = 2;
- $model->save();
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|