| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace addons\WechatVideoShop\common\service;
- use addons\WechatVideoShop\common\models\WechatVideoShopGoodsSetting;
- use common\traits\ErrorTrait;
- use yii\helpers\Json;
- class GoodsSettingService
- {
- use ErrorTrait;
- /**
- * 商品模式全局调用
- * @param array $params
- * @return mixed|null
- */
- public static function globalGoodsModel(array $params)
- {
- $data = WechatVideoShopGoodsSetting::getOne($params['where'], true);
- if (!empty($data['config'])) {
- $config = Json::decode($data['config']);
- ksort($config);
- $data['config'] = Json::encode($config);
- }
- return $data;
- }
- /**
- * 商品模式更新数据
- * @param array $params
- * @param array $data
- * @return bool
- */
- public static function setData(array $params, array $data)
- {
- try {
- $model = WechatVideoShopGoodsSetting::getOne([
- ['mall_id' => $params['mall_id']],
- ['item_id' => $params['item_id']]
- ]);
- if (empty($model)) {
- $model = new WechatVideoShopGoodsSetting();
- $model->mall_id = $params['mall_id'];
- $model->item_id = $params['item_id'];
- }
- $config = $data['config'];
- ksort($config);
- $model->is_enable = $data['is_enable'];
- $model->config = $config;
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @return string
- */
- public static function getErrorMessage()
- {
- return self::$static_error;
- }
- }
|