Order.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 产品管理
  7. */
  8. namespace app\bestbao\controller;
  9. use app\common\facade\Inform;
  10. use app\bestbao\model\BestbaoEngineer;
  11. use app\bestbao\model\BestbaoOrder;
  12. use app\bestbao\model\BestbaoProduct;
  13. use think\facade\Request;
  14. use think\helper\Time;
  15. class Order extends Common{
  16. public function initialize(){
  17. parent::initialize();
  18. $this->assign('pathMaps',[['name'=>'订单管理','url'=>'javascript:;']]);
  19. }
  20. /**
  21. * 列表
  22. */
  23. public function index(){
  24. $condition = [];
  25. $keyword = Request::param('keyword');
  26. $state = Request::param('state/s');
  27. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  28. if (!empty($keyword)) {
  29. $condition[] = ['title', 'like', '%' . $keyword . '%'];
  30. }
  31. if($state != ''){
  32. $condition[] = ['state', '=', $state];
  33. }
  34. $time = Request::param('time/d',0);
  35. if($time){
  36. switch ($time) {
  37. case 2:
  38. list($start, $end) = Time::yesterday();
  39. break;
  40. case 30:
  41. list($start, $end) = Time::month();
  42. break;
  43. case 60:
  44. list($start, $end) = Time::lastMonth();
  45. break;
  46. default:
  47. list($start, $end) = Time::today();
  48. break;
  49. }
  50. $condition[] = ['create_time','>=',$start];
  51. $condition[] = ['create_time','<=',$end];
  52. }
  53. $starttime = Request::param('starttime/s');
  54. $endtime = Request::param('endtime/s');
  55. if($starttime){
  56. $condition[] = ['create_time','>=',strtotime($starttime)];
  57. }
  58. if($endtime){
  59. $condition[] = ['create_time','<=',strtotime($endtime)];
  60. }
  61. $view['lists'] = BestbaoOrder::where($condition)->order('create_time desc')->paginate(15, false, ['query' => ['keyword' => $keyword, 'time' => $time, 'starttime' => $starttime, 'endtime' => $endtime]]);
  62. $view['time'] = $time;
  63. $view['starttime'] = $starttime;
  64. $view['endtime'] = $endtime;
  65. $view['state'] = $state;
  66. $view['keyword'] = $keyword;
  67. return view()->assign($view);
  68. }
  69. /**
  70. * @param int $id
  71. * @return \think\response\View
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. * @throws \think\exception\DbException
  75. * 订单详情
  76. */
  77. public function detail(int $id = 0){
  78. $info = BestbaoOrder::where(['id' => $id])->find();
  79. $view['imgs'] = empty($info->imgs) ? '' : json_decode($info->imgs);
  80. $view['info'] = $info;
  81. return view()->assign($view);
  82. }
  83. /**
  84. * @return \think\response\Json|\think\response\View
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. * @throws \think\exception\DbException
  88. * 添加订单
  89. */
  90. public function add(){
  91. if(request()->isAjax()){
  92. $data = [
  93. 'member_miniapp_id' => $this->member_miniapp_id,
  94. 'title' => input('post.title/s'),
  95. 'question' => input('post.question/s'),
  96. 'realname' => input('post.realname/s'),
  97. 'phone' => input('post.phone/s'),
  98. 'address' => input('post.address/s'),
  99. 'urgent' => input('post.urgent/d'),
  100. 'uid' => input('post.uid/d'),
  101. 'state' => 0,
  102. 'product_id' => input('post.product_id/d'),
  103. 'imgs' => json_encode(input('post.imgs/a')),
  104. 'create_time' => time(),
  105. 'update_time' => time(),
  106. ];
  107. $validate = $this->validate($data,'Order.add');
  108. if(true !== $validate){
  109. return enjson(0,$validate);
  110. }
  111. $result = BestbaoOrder::create($data);
  112. if($result){
  113. //通知到工程师
  114. $list = BestbaoEngineer::where(['member_miniapp_id' => $this->member_miniapp_id])->select()->toArray();
  115. foreach ($list as $info){
  116. Inform::sms($info['uid'],$this->member_miniapp_id,['title' =>'业务进展通知','type' => '新订单申请','content' =>'您有新的订单待待处理','state' => '待处理']);
  117. }
  118. return enjson(200,'操作成功',['url'=>url('order/index')]);
  119. }else{
  120. return enjson(0,'操作失败');
  121. }
  122. }else{
  123. return view();
  124. }
  125. }
  126. /**
  127. * @return \think\response\View
  128. * @throws \think\exception\DbException
  129. * 查找产品
  130. */
  131. public function selectProduct(){
  132. $keyword = Request::param('keyword/s');
  133. $input = Request::param('input/s');
  134. $view['list'] = BestbaoProduct::where(['member_miniapp_id' => $this->member_miniapp_id])->where('title', 'like', '%' . $keyword . '%')->order('create_time desc')->paginate(20);
  135. $view['keyword'] = $keyword;
  136. $view['input'] = $input;
  137. $view['id'] = $this->member_miniapp_id;
  138. return view()->assign($view);
  139. }
  140. /**
  141. * @return \think\response\Json|\think\response\View
  142. * @throws \think\db\exception\DataNotFoundException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. * @throws \think\exception\DbException
  145. * 修改订单
  146. */
  147. public function edit(){
  148. if(request()->isAjax()){
  149. $data = [
  150. 'id' => input('post.id/d'),
  151. 'member_miniapp_id' => $this->member_miniapp_id,
  152. 'title' => input('post.title/s'),
  153. 'question' => input('post.question/s'),
  154. 'realname' => input('post.realname/s'),
  155. 'phone' => input('post.phone/s'),
  156. 'address' => input('post.address/s'),
  157. 'urgent' => input('post.urgent/d'),
  158. 'uid' => input('post.uid/d'),
  159. 'state' => 0,
  160. 'product_id' => input('post.product_id/d'),
  161. 'imgs' => json_encode(input('post.imgs/a')),
  162. 'update_time' => time(),
  163. ];
  164. $validate = $this->validate($data,'Order.edit');
  165. if(true !== $validate){
  166. return enjson(0,$validate);
  167. }
  168. $result = BestbaoOrder::update($data);
  169. if($result){
  170. return enjson(200,'操作成功',['url'=>url('order/index')]);
  171. }else{
  172. return enjson(0,'操作失败');
  173. }
  174. }else{
  175. $id = input('id/d');
  176. $info = BestbaoOrder::where(['id' => $id])->find();
  177. $view['imgs'] = json_decode($info['imgs'],true);
  178. $view['info'] = $info;
  179. return view()->assign($view);
  180. }
  181. }
  182. /**
  183. * @return \think\response\Json
  184. * @throws \think\Exception
  185. * @throws \think\exception\PDOException
  186. * 修改订单
  187. */
  188. public function delete(){
  189. $id = input('id/d');
  190. $result = BestbaoOrder::where(['id' => $id])->delete();
  191. if($result){
  192. return enjson(200,'操作成功');
  193. }else{
  194. return enjson(0,'操作失败');
  195. }
  196. }
  197. /**
  198. * @return \think\response\Json
  199. * @throws \think\Exception
  200. * @throws \think\exception\PDOException
  201. * 修改订单
  202. */
  203. public function end(){
  204. $id = input('id/d');
  205. $result = BestbaoOrder::where(['id' => $id])->update(['state' => 2]);
  206. if($result){
  207. return enjson(200,'操作成功');
  208. }else{
  209. return enjson(0,'操作失败');
  210. }
  211. }
  212. }