| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Admin;
- use app\models\Option;
- use yii\base\Model;
- use app\models\Store;
- use app\constants\OptionSetting;
- class SettingForm extends Model
- {
- public $data = [];
- public function save($store_id = 0)
- {
- $oldQQMapKey = Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'store', '')['value'])['value'];
- if ($this->data) {
- foreach ($this->data as $val) {
- if (count($val['list']) > 0) {
- $res = Option::verifyData($val['list'], $val['key']);
- if ($res && $res['code'] > 0) {
- return $res;
- }
- }
- }
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($this->data as $val) {
- $res = Option::setGroup($val['key'],$val['list'], $store_id ?: \get_store_id());
- if ( $res !== true) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '保存失败',
- 'err' => $res
- ];
- }
- }
- $this->upStore($store_id);
- $t->commit();
- \app\utils\UpdateAfter::UpdateQQMapKey($oldQQMapKey);
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- }
-
- private function upStore($store_id = 0){
- $store_id = $store_id ? $store_id : get_store_id();
- $store = Store::findOne($store_id);
- $name = Option::get('name', $store->id);
- $logo = Option::get('logo', $store->id);
- $coordinate = Option::get('coordinate', $store->id);
- $address_info = Option::get('address_info', $store->id);
- $address = Option::get('address', $store->id);
- $address_info = json_decode($address_info['value'], true);
- if (!empty($address_info)) {
- $store->province_id = $address_info['province_id'];
- $store->city_id = $address_info['city_id'];
- $store->district_id = $address_info['district_id'];
- }
- if (!empty($address['value'])) {
- $store->address = $address['value'];
- }
- if (!empty($coordinate['value'])) {
- $store->coordinate = $coordinate['value'];
- $coordinate = explode(',', $coordinate['value']);
- $store->longitude = $coordinate[1];
- $store->latitude = $coordinate[0];
- }
- if ($name['value']) {
- $store->name = $name['value'];
- }
- if ($logo['value']) {
- $store->logo = $logo['value'];
- }
- $contact_tel = Option::get('contact_tel', $store->id)['value'];
- $store->contact_tel = $contact_tel;
- $store->save();
- $admin = Admin::findOne(['OR', ['type' => 'store', 'type_id' => $store->id, 'is_delete' => 0], ['id' => $store->admin_id]]);
- if ($admin) {
- $admin->mobile = $contact_tel;
- $admin->save();
- }
- }
-
- public static function staticUpStore($store_id) {
- $self = new self();
- $self->upStore($store_id);
- }
- }
|