where([ 'mall_id' => $mallId, ]) ->asArray() ->one(); if (empty($model)) { return []; } $model['payment_type'] = json_decode($model['payment_type'], true); $model['send_type'] = json_decode($model['send_type'], true); !empty($model['background_imgs']) ? $model['background_imgs'] = json_decode($model['background_imgs'], true) : ''; $model['start_at'] = date('Y-m-d H:i:s', $model['start_at']); $model['end_at'] = date('Y-m-d H:i:s', $model['end_at']); return $model; } catch (\ErrorException $errorException) { throw new \ErrorException($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @param $mallId * @param $params * @return array * @throws \ErrorException */ public static function saveData($mallId, $params) { try { $model = ScratchSettingModel::findOne([ 'mall_id' => $mallId, ]); if (!$model) { $model = new ScratchSettingModel(); $model->mall_id = $mallId; } $params['payment_type'] = json_encode($params['payment_type'], JSON_UNESCAPED_UNICODE); $params['send_type'] = json_encode($params['send_type'], JSON_UNESCAPED_UNICODE); $backgroundImgs = ScratchSettingModel::getBackgroundImgs(); if(!PublicLogic::isHttp($params['background_imgs']['image'])){ $params['background_imgs']['image'] = $backgroundImgs['image']; } $model->title = $params['title'] ?? ''; $model->type = $params['type']; $model->probability = $params['probability']; $model->oppty = $params['oppty']; $model->deplete_integral_num = $params['deplete_integral_num'] ?? 0; $model->rule = $params['rule']; $model->payment_type = $params['payment_type']; $model->send_type = $params['send_type']; $model->is_sms = $params['is_sms']; $model->is_wechat = $params['is_wechat']; $model->is_mail = $params['is_mail']; $model->is_print = $params['is_print']; $model->start_at = strtotime($params['start_at']); $model->end_at = strtotime($params['end_at']); $model->background_imgs = json_encode($params['background_imgs'], JSON_UNESCAPED_UNICODE); if (!$model->save()) { throw new \ErrorException($model->getErrorMessage()); } return true; } catch (\ErrorException $errorException) { throw new \ErrorException($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @param $param * @return array * @throws \Exception */ public static function saveBackground($mallId, $param){ try { $model = ScratchSettingModel::findOne(['mall_id' => $mallId]); if(!$model){ $model = new ScratchSettingModel(); $model->mall_id = $mallId; } $backgroundImgs = ScratchSettingModel::getBackgroundImgs(); if(!PublicLogic::isHttp($param['image'])){ $param['image'] = $backgroundImgs['image']; } $model->background_imgs = json_encode($param,JSON_UNESCAPED_UNICODE); if (!$model->save()) { throw new \Exception($model->getErrorMessage()); } return true; } catch (\ErrorException $errorException) { throw new \ErrorException($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } }