| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace addons\Scratch\common\logic;
- use addons\Coupon\common\models\AddonsCoupon;
- use addons\Scratch\common\enums\ScratchEnum;
- use addons\Scratch\common\models\ScratchCouponModel;
- use addons\Scratch\common\models\ScratchLogModel;
- use addons\Scratch\common\models\ScratchModel;
- use addons\Scratch\common\models\ScratchSettingModel;
- use common\models\base\User;
- use common\models\goods\Goods;
- use common\models\goods\GoodsAttr;
- use common\models\mall\MallAddons;
- use phpDocumentor\Reflection\Types\True_;
- /**
- * Class ScratchSettingLogic
- * @package addons\Scratch\common\logic
- */
- class ScratchSettingLogic
- {
- /**
- * @param $id
- * @return array|false|mixed|void
- * @throws \ErrorException
- */
- public static function getData($mallId)
- {
- try {
- $model = ScratchSettingModel::find()
- ->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());
- }
- }
- }
|