12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\store\controller;
- use library\Controller;
- use think\Db;
- class ExpressTemplate extends Controller
- {
-
- protected $table = 'StoreExpressTemplate';
-
- public function index()
- {
- $this->title = '邮费模板管理';
- $filename = env('root_path') . 'public/static/plugs/jquery/area/area.json';
- $this->provinces = array_column(json_decode(file_get_contents($filename), true), 'name');
- $this->list = Db::name($this->table)->where(['is_default' => '0'])->select();
- foreach ($this->list as &$item) $item['rule'] = explode(',', $item['rule']);
- $this->default = Db::name($this->table)->where(['is_default' => '1'])->find();
- $this->fetch();
- }
-
- public function save()
- {
- list($list, $idxs, $post) = [[], [], $this->request->post()];
- foreach (array_keys($post) as $key) if (stripos($key, 'order_reduction_state_') !== false) {
- $idxs[] = str_replace('order_reduction_state_', '', $key);
- }
- foreach (array_unique($idxs) as $index) if (!empty($post["rule_{$index}"])) $list[] = [
- 'rule' => join(',', $post["rule_{$index}"]),
-
- 'order_reduction_state' => $post["order_reduction_state_{$index}"],
- 'order_reduction_price' => $post["order_reduction_price_{$index}"],
-
- 'first_number' => $post["first_number_{$index}"],
- 'first_price' => $post["first_price_{$index}"],
-
- 'next_number' => $post["next_number_{$index}"],
- 'next_price' => $post["next_price_{$index}"],
-
- 'is_default' => $post["is_default_{$index}"],
- ];
- if (empty($list)) $this->error('请配置有效的邮费规则');
- Db::name($this->table)->where('1=1')->delete();
- Db::name($this->table)->insertAll($list);
- $this->success('邮费规则配置成功!');
- }
- }
|