| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\QiShangTong\backend\controllers;
- use addons\QiShangTong\common\service\GoodsService;
- use addons\QiShangTong\common\service\SettingService;
- use common\enums\StatusEnum;
- use common\models\common\PlatformSetting;
- use common\models\mall\Mall;
- use Yii;
- use yii\helpers\Json;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\WechatVideoShop\backend\controllers
- */
- class SettingController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- $service = (new SettingService());
- if (Yii::$app->request->isPost) {
- $data = Yii::$app->request->post();
- $valid = Yii::$app->services->validate->validate($data, [
- [['is_enable', 'is_default', 'auto_update_price'], 'integer'],
- [['app_key', 'secret_key', 'contact_image'], 'string'],
- [['market_price_rate', 'price_rate', 'min_balance'], 'number'],
- [['price', 'mobile'], 'safe'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data['price'] = !empty($data['price']) ? Json::encode($data['price']) : '[]';
- if (!empty($data['is_default']) && $this->admin->admin_type == StatusEnum::ENABLED) {
- // 需要将其他的更新为非默认
- foreach (Mall::getAllMallIds() as $mallId) {
- if ($mallId != $this->mall_id) {
- $config = $service->get($mallId);
- $config['is_default'] = StatusEnum::DISABLED;
- $service->save($mallId, $config);
- }
- }
- }
- if (!empty($data['auto_update_price'])) {
- $ret = $service->get($this->mall_id);
- // 判断订单是否更改
- if (!empty($ret['price']) && (md5($ret['price']) != md5($data['price']))) {
- // 需要更新商品价格
- try {
- (new GoodsService())->changePrice($this->mall_id);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $service->save($this->mall_id, $data) ? $this->success("保存成功", $data) : $this->error('保存失败');
- } else {
- $ret = $service->get($this->mall_id);
- if (!empty($ret['price'])) {
- $ret['price'] = Json::decode($ret['price']);
- if (!is_array($ret['price']['price']['rate'])) $ret['price'] = null;
- }
- return $this->success('success', $ret);
- }
- }
- $get_system_setting = PlatformSetting::getConfByGroup('system', true);
- return $this->render('index',[
- 'order_ship_callback_url' => "{$get_system_setting['api_url']['value']}/qi-shang-tong/v1/order/delivery",
- 'order_ready_callback_url' => "{$get_system_setting['api_url']['value']}/qi-shang-tong/v1/order/ready",
- 'order_refund_callback_url' => "{$get_system_setting['api_url']['value']}/qi-shang-tong/v1/refund/event",
- 'goods_callback_url' => "{$get_system_setting['api_url']['value']}/qi-shang-tong/v1/goods/event",
- 'admin_type' => $this->admin->admin_type]);
- }
- }
|