ExpressTemplate.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use library\tools\Data;
  5. use think\Db;
  6. /**
  7. * 邮费模板管理
  8. * Class ExpressTemplate
  9. * @package app\store\controller
  10. */
  11. class ExpressTemplate extends Controller
  12. {
  13. /**
  14. * 指定数据表
  15. * @var string
  16. */
  17. protected $table = 'StoreExpressTemplate';
  18. /**
  19. * 邮费模板管理
  20. */
  21. public function index()
  22. {
  23. $this->title = '邮费模板管理';
  24. }
  25. /**
  26. * 显示邮费模板
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. */
  31. protected function _index_get()
  32. {
  33. $this->provinces = Db::name('StoreExpressProvince')->where(['status' => '1'])->order('sort asc,id desc')->column('title');
  34. $this->list = Db::name($this->table)->where(['is_default' => '0'])->select();
  35. foreach ($this->list as &$item) $item['rule'] = explode(',', $item['rule']);
  36. $this->default = Db::name($this->table)->where(['is_default' => '1'])->find();
  37. $this->fetch();
  38. }
  39. /**
  40. * 保存邮费模板
  41. * @throws \think\Exception
  42. * @throws \think\exception\PDOException
  43. */
  44. protected function _index_post()
  45. {
  46. list($list, $idxs, $post) = [[], [], $this->request->post()];
  47. foreach (array_keys($post) as $key) if (stripos($key, 'order_reduction_state_') !== false) {
  48. $idxs[] = str_replace('order_reduction_state_', '', $key);
  49. }
  50. foreach (array_unique($idxs) as $index) if (!empty($post["rule_{$index}"])) $list[] = [
  51. 'rule' => join(',', $post["rule_{$index}"]),
  52. // 订单满减配置
  53. 'order_reduction_state' => $post["order_reduction_state_{$index}"],
  54. 'order_reduction_price' => $post["order_reduction_price_{$index}"],
  55. // 首件邮费配置
  56. 'first_number' => $post["first_number_{$index}"],
  57. 'first_price' => $post["first_price_{$index}"],
  58. // 首件邮费配置
  59. 'next_number' => $post["next_number_{$index}"],
  60. 'next_price' => $post["next_price_{$index}"],
  61. // 默认邮费规则
  62. 'is_default' => $post["is_default_{$index}"],
  63. ];
  64. if (empty($list)) $this->error('请配置有效的邮费规则');
  65. Db::name($this->table)->where('1=1')->delete();
  66. Db::name($this->table)->insertAll($list);
  67. $this->success('邮费规则配置成功!');
  68. }
  69. }