diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index 53df79e6..93d22a2e 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -22,7 +22,8 @@ use think\db\exception\ModelNotFoundException; use app\api\validate\store\Store as StoreValidte; use \app\common\model\Store as StoreInfoModel; use app\common\model\UploadFile; - +use app\common\model\PriceSet; +use think\Db; /** * 商城基础信息 * Class Store @@ -93,9 +94,16 @@ class Store extends Controller { $params = $this->request->param(); $storeid = request()->header()['storeid']; - $upData = [ - 'group_share_img_id'=>$params['group_share_img_id']??0 - ]; + $upData = []; + if (isset($params['group_share_img_id']) && $params['group_share_img_id']) { + $upData['group_share_img_id'] = $params['group_share_img_id']; + } + if (isset($params['min_profit']) && $params['min_profit']) { + $upData['min_profit'] = $params['min_profit']; + } + if (!$upData) { + return $this->renderSuccess('ok'); + } StoreInfoModel::where('store_id',$storeid)->update($upData); return $this->renderSuccess('ok'); } @@ -121,6 +129,87 @@ class Store extends Controller return $this->renderSuccess($list->toArray()); } + public function setStorePrice(): Json + { + $params = $this->request->param(); + $storeid = request()->header()['storeid']; + // var_dump($params); + // exit(); + //先删除 + PriceSet::where('store_id', $storeid)->where('type', $params['type']??0)->delete(); + $inDatas = []; + foreach ($params['list'] as $value) { + foreach ($value['price_list'] as $price) { + $temp = [ + 'category' => $value['category'], + 'store_id' => $storeid, + 'type' => $params['type'], + 'min' => $price['min'], + 'max' => $price['max'], + 'add_price_rate' => $price['add_price_rate'], + 'create_time' => time(), + 'update_time' => time(), + ]; + $inDatas[] = $temp; + } + + } + // echo "
"; + // print_r($inDatas); + // exit(); + $model = new PriceSet; + $model->addAll($inDatas); + return $this->renderSuccess('ok'); + } + //加个设置回显 + public function getStorePriceInfo(int $type): Json + { + $storeid = request()->header()['storeid']; + $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray(); + $data = []; + $arr = []; + foreach ($list as $value) { + $arr[$value['category']][] = $value; + } + foreach ($arr as $key => $item) { + $data['list'][] = [ + 'category' => $key, + 'price_list' => $item, + ]; + } + $data['type'] = $type; + return $this->renderSuccess($data); + } + + //加个设置回显 + public function test(int $type): Json + { + $storeid = request()->header()['storeid']; + $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray(); + $data = []; + $arr = []; + foreach ($list as $value) { + $arr[$value['category']][] = $value; + } + foreach ($arr as $key => $item) { + $data['list'][] = [ + 'category' => $key, + 'price_list' => $item, + ]; + } + $data['type'] = $type; + return $this->renderSuccess($data); + } + + + + + + + + + + } \ No newline at end of file diff --git a/app/common/model/PriceSet.php b/app/common/model/PriceSet.php new file mode 100644 index 00000000..bf2766e4 --- /dev/null +++ b/app/common/model/PriceSet.php @@ -0,0 +1,31 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\HasOne; +use app\common\model\store\Shop; +/** + * 活动栏目模型类 + * Class User + * @package app\common\model + */ +class PriceSet extends BaseModel +{ + // 定义表名 + protected $name = 'price_set'; + + // 定义主键 + protected $pk = 'id'; + +} diff --git a/app/store/model/store/Shop.php b/app/store/model/store/Shop.php index fc463ac7..75557589 100644 --- a/app/store/model/store/Shop.php +++ b/app/store/model/store/Shop.php @@ -88,6 +88,7 @@ class Shop extends ShopModel if (!$this->validateForm($data)) { return false; } + $data['remark'] = json_encode($data['remark'], JSON_UNESCAPED_UNICODE); return $this->save($this->createData($data)); } @@ -101,6 +102,7 @@ class Shop extends ShopModel if (!$this->validateForm($data)) { return false; } + $data['remark'] = json_encode($data['remark'], JSON_UNESCAPED_UNICODE); return $this->save($this->createData($data)) !== false; }