RenovatePriceSeet.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\View;
  4. use think\facade\Db;
  5. use app\model\RenovatePrice;
  6. use app\model\RenovatePriceItem;
  7. use app\BaseController;
  8. class RenovatePriceSeet extends BaseController
  9. {
  10. /**
  11. * 设置报价页面
  12. */
  13. public function price_setting()
  14. {
  15. $request = request();
  16. $root_id = request()->employee->root_id;
  17. if (!$request->isAjax()) {
  18. $list = RenovatePrice::where([['root_id','=',$root_id],['status','=',0]])->order('sort desc')->select()->toArray();
  19. View::assign('list',$list);
  20. return View::fetch();
  21. }
  22. }
  23. /**
  24. * 套餐项目列表
  25. */
  26. public function package_itemlist()
  27. {
  28. $request = request();
  29. $root_id = request()->employee->root_id;
  30. $param = $this->request->only(['id']);
  31. if (!$request->isAjax()) {
  32. return View::fetch();
  33. }
  34. $list = RenovatePriceItem::where([['pid','=',$param['id']],['root_id','=',$root_id]])->select()->toArray();
  35. return json(['code'=>0,'msg'=>'获取成功','data'=>$list]);
  36. }
  37. /**
  38. * 添加报价套餐
  39. */
  40. public function add_renovate_package()
  41. {
  42. $request = request();
  43. $root_id = request()->employee->root_id;
  44. $param = $this->request->only(['id'=>'','package_name','service_price','devise_price']);
  45. if (!$request->isAjax()) {
  46. if(!empty($param['id'])){
  47. $packdata = RenovatePrice::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  48. View::assign('packdata',$packdata);
  49. }
  50. View::assign('id',$param['id']);
  51. return View::fetch();
  52. }
  53. $add = [
  54. 'package_name'=>$param['package_name'],
  55. 'root_id' => $root_id,
  56. 'service_price' => $param['service_price'],
  57. 'devise_price' => $param['devise_price']
  58. ];
  59. $ms = RenovatePrice::insertGetId($add);
  60. if($ms){
  61. return json(['code' => 0, 'msg' => '添加成功']);
  62. }else{
  63. return json(['code' => 1, 'msg' => '添加失败']);
  64. }
  65. }
  66. /**
  67. * 添加套餐的项目
  68. */
  69. public function add_package_item()
  70. {
  71. $request = request();
  72. $root_id = request()->employee->root_id;
  73. $param = $this->request->only(['id'=>'','name','rule','price','remark','pid'=>'','discount_price']);
  74. if (!$request->isAjax()) {
  75. if(!empty($param['id'])){
  76. $itemdata = RenovatePriceItem::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  77. View::assign('itemdata',$itemdata);
  78. }
  79. View::assign('pid',$param['pid']);
  80. View::assign('id',$param['id']);
  81. //var_dump($param['id']);exit;
  82. return View::fetch();
  83. }
  84. if(empty($param['pid'])) return json(['code'=>1,'msg'=>'参数错误']);
  85. $check = RenovatePrice::where([['root_id','=',$root_id],['id','=',$param['pid']]])->find();
  86. if(empty($check)) return json(['code'=>1,'msg'=>'套餐不存在']);
  87. $add = [
  88. 'name' => $param['name'],
  89. 'rule' => $param['rule'],
  90. 'price' => $param['price'],
  91. 'pid' => $param['pid'],
  92. 'remark' => $param['remark'],
  93. 'root_id' => $root_id,
  94. 'discount_price' => $param['discount_price']
  95. ];
  96. $ms = RenovatePriceItem::insertGetId($add);
  97. if($ms){
  98. return json(['code' => 0, 'msg' => '添加成功']);
  99. }else{
  100. return json(['code' => 1, 'msg' => '添加失败']);
  101. }
  102. }
  103. /**
  104. * 修改套餐
  105. */
  106. public function edit_package()
  107. {
  108. $request = request();
  109. $root_id = request()->employee->root_id;
  110. $param = $this->request->only(['id','package_name','service_price','devise_price','remark'=>'']);
  111. if (!$request->isAjax()) {
  112. //View::assign('source_list',$source_list);
  113. return View::fetch();
  114. }
  115. $pkdata = RenovatePrice::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  116. if(empty($pkdata)) return json(['code'=>1,'msg'=>'数据不存在']);
  117. $pkdata->package_name = $param['package_name'];
  118. $pkdata->service_price = $param['service_price'];
  119. $pkdata->devise_price = $param['devise_price'];
  120. $pkdata->remark = $param['remark'];
  121. $pkdata->save();
  122. return json(['code' => 0, 'msg' => '修改成功']);
  123. }
  124. /**
  125. * 修改套餐项目
  126. */
  127. public function edit_packitem()
  128. {
  129. $request = request();
  130. $root_id = request()->employee->root_id;
  131. $param = $this->request->only(['id','name','rule','price','pid','remark','discount_price']);
  132. if (!$request->isAjax()) {
  133. return View::fetch();
  134. }
  135. $itdata = RenovatePriceItem::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  136. if(empty($itdata)) return json(['code'=>1,'msg'=>'数据不存在']);
  137. $itdata->name = $param['name'];
  138. $itdata->rule = $param['rule'];
  139. $itdata->price = $param['price'];
  140. $itdata->remark = $param['remark'];
  141. $itdata->discount_price = $param['discount_price'];
  142. $itdata->save();
  143. return json(['code' => 0, 'msg' => '修改成功']);
  144. }
  145. /**
  146. * 删除套餐
  147. */
  148. public function del_package()
  149. {
  150. $request = request();
  151. $root_id = request()->employee->root_id;
  152. $param = $this->request->only(['id']);
  153. $pkdata = RenovatePrice::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  154. if(empty($pkdata)) return json(['code'=>1,'msg'=>'数据不存在']);
  155. $item = RenovatePriceItem::where([['root_id','=',$root_id],['pid','=',$param['id']]])->count();
  156. if(!empty($item)) return json(['code'=>1,'msg'=>'请先删除套餐下面的项目']);
  157. $pkdata->delete();
  158. return json(['code' => 0, 'msg' => '删除成功']);
  159. }
  160. /**
  161. * 删除套餐下的项目
  162. */
  163. public function del_packitem()
  164. {
  165. $request = request();
  166. $root_id = request()->employee->root_id;
  167. $param = $this->request->only(['id']);
  168. $pkdata = RenovatePriceItem::where([['root_id','=',$root_id],['id','=',$param['id']]])->find();
  169. if(empty($pkdata)) return json(['code'=>1,'msg'=>'数据不存在']);
  170. $pkdata->delete();
  171. return json(['code' => 0, 'msg' => '删除成功']);
  172. }
  173. }