FreightTemplate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. use think\view\driver\Think;
  6. /**
  7. * 运费模板
  8. * Class Goods
  9. * @package app\store\controller
  10. */
  11. class FreightTemplate extends Controller
  12. {
  13. /**
  14. * 绑定数据表
  15. * @var string
  16. */
  17. protected $table = 'FreightTemplate';
  18. /**
  19. * 运费模板管理
  20. * @auth true
  21. * @menu true
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @throws \think\exception\PDOException
  27. */
  28. public function index()
  29. {
  30. $this->title = '运费模板';
  31. $query = $this->_query($this->table)->where('is_deleted',0)->like('name');
  32. $query->order('status desc , sort desc , id desc')->page();
  33. }
  34. /**
  35. * 数据列表处理
  36. * @auth true
  37. * @menu true
  38. * @param array $data
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. protected function _index_page_filter(&$data)
  44. {
  45. }
  46. /**
  47. * 添加运费模板
  48. * @auth true
  49. * @menu true
  50. * @throws \think\Exception
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. * @throws \think\exception\PDOException
  55. */
  56. public function add()
  57. {
  58. $this->title = '添加运费模板';
  59. if(input('reloaded') !=1) {
  60. echo "<script>
  61. location.href=location.href+'&reloaded=1';
  62. location.reload();
  63. </script>";
  64. }
  65. $this->city_area = get_city_area();
  66. $this->_form($this->table, 'form');
  67. }
  68. /**
  69. * 编辑运费模板
  70. * @auth true
  71. * @menu true
  72. * @throws \think\Exception
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. * @throws \think\exception\PDOException
  77. */
  78. public function edit()
  79. {
  80. $this->title = '编辑运费模板';
  81. $this->jump = input('jump',0);
  82. if(input('reloaded') !=1) {
  83. echo "<script>
  84. location.href=location.href+'&reloaded=1';
  85. location.reload();
  86. </script>";
  87. }
  88. $this->city_area = get_city_area();
  89. $this->_form($this->table, 'form');
  90. }
  91. /**
  92. * 禁用
  93. * @auth true
  94. * @menu true
  95. * @throws \think\Exception
  96. * @throws \think\exception\PDOException
  97. */
  98. public function forbidden()
  99. {
  100. $this->_save($this->table, ['status' => '0']);
  101. }
  102. /**
  103. * 启用
  104. * @auth true
  105. * @menu true
  106. * @throws \think\Exception
  107. * @throws \think\exception\PDOException
  108. */
  109. public function enable()
  110. {
  111. $this->_save($this->table, ['status' => 1]);
  112. }
  113. /**
  114. * 删除
  115. * @auth true
  116. * @menu true
  117. * @throws \think\Exception
  118. * @throws \think\exception\PDOException
  119. */
  120. public function del()
  121. {
  122. $this->_save($this->table, ['is_deleted' => 1]);
  123. }
  124. /* 表单数据处理
  125. * @auth true
  126. * @menu true
  127. * @param array $data
  128. */
  129. protected function _form_filter(&$data)
  130. {
  131. // 添加或编辑模板
  132. if ($this->request->isPost()) {
  133. $custom_num = count($data['first_num']);
  134. $custom_data = [];
  135. for ($i= 0;$i < $custom_num;$i++) {
  136. $custom_data[$i]['express'] = $data['express'][$i];
  137. $custom_data[$i]['first_num'] = $data['first_num'][$i] > 0 ? intval($data['first_num'][$i]):0;
  138. $custom_data[$i]['first_price'] = $data['first_price'][$i]> 0 ? number_format($data['first_price'][$i],2) :0 ;
  139. $custom_data[$i]['keep_price'] = $data['keep_price'][$i] > 0 ? number_format($data['keep_price'][$i],2) :0 ;
  140. }
  141. $data['custom'] = json_encode($custom_data);
  142. }
  143. }
  144. protected function _form_result($result)
  145. {
  146. $this->success('保存成功',$_SERVER['HTTP_REFERER'].'#/store/freight_template/index');
  147. }
  148. }