InfoController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 新品列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-12-20 10:09:42
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Furniture\Newgoods;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\FurnitureNewgoodsBookingModel;
  12. use App\Models\FurnitureNewgoodsCommentModel;
  13. use App\Models\FurnitureNewgoodsInfoModel;
  14. use Illuminate\Http\Request;
  15. use App\Repositories\Base\Criteria\OrderBy;
  16. use App\Repositories\Furniture\Newgoods\Criteria\MultiWhere;
  17. use App\Repositories\Furniture\Newgoods\InfoRepository;
  18. class InfoController extends Controller
  19. {
  20. private $repository;
  21. public function __construct(InfoRepository $repository)
  22. {
  23. if (!$this->repository) $this->repository = $repository;
  24. }
  25. function index(Request $request)
  26. {
  27. $search['keyword'] = $request->input('keyword');
  28. $search['store_id'] = $this->getStoreId();
  29. $query = $this->repository->pushCriteria(new MultiWhere($search));
  30. if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  31. $query = $query->pushCriteria(new OrderBy($request['sort_field'], $request['sort_field_by']));
  32. }
  33. $list = $query->paginate(20);
  34. return view('admin.furniture.newgoods.info.index', compact('list'));
  35. }
  36. function check(Request $request)
  37. {
  38. $request = $request->all();
  39. $search['keyword'] = $request->input('keyword');
  40. $orderby = array();
  41. if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  42. $orderby[$request['sort_field']] = $request['sort_field_by'];
  43. }
  44. $list = $this->repository->search($search, $orderby);
  45. return view('admin.furniture.newgoods.info.check', compact('list'));
  46. }
  47. /**
  48. * 添加
  49. *
  50. */
  51. public function create(Request $request)
  52. {
  53. if ($request->method() == 'POST') {
  54. return $this->_createSave();
  55. }
  56. return view('admin.furniture.newgoods.info.edit');
  57. }
  58. /**
  59. * 保存修改
  60. */
  61. private function _createSave()
  62. {
  63. $data = (array)request('data');
  64. $data['store_id'] =$this->getStoreId();
  65. $id = $this->repository->create($data);
  66. if ($id) {
  67. $url[] = array('url' => U('Furniture/Newgoods/Info/index'), 'title' => '返回列表');
  68. $url[] = array('url' => U('Furniture/Newgoods/Info/create'), 'title' => '继续添加');
  69. $this->showMessage('添加成功', $url);
  70. } else {
  71. $url[] = array('url' => U('Furniture/Newgoods/Info/index'), 'title' => '返回列表');
  72. return $this->showWarning('添加失败', $url);
  73. }
  74. }
  75. /**
  76. *
  77. * 修改
  78. *
  79. *
  80. */
  81. public function update(Request $request)
  82. {
  83. if ($request->method() == 'POST') {
  84. return $this->_updateSave();
  85. }
  86. $data = $this->repository->find($request->get('id'));
  87. return view('admin.furniture.newgoods.info.edit', compact('data'));
  88. }
  89. /**
  90. * 保存修改
  91. */
  92. private function _updateSave()
  93. {
  94. $data = (array)request('data');
  95. $ok = $this->repository->update(request('id'), $data);
  96. if ($ok) {
  97. $url[] = array('url' => U('Furniture/Newgoods/Info/index'), 'title' => '返回列表');
  98. return $this->showMessage('操作成功', urldecode(request('_referer')));
  99. } else {
  100. $url[] = array('url' => U('Furniture/Newgoods/Info/index'), 'title' => '返回列表');
  101. return $this->showWarning('操作失败', $url);
  102. }
  103. }
  104. public function view(Request $request)
  105. {
  106. $data = $this->repository->find(request('id'));
  107. return view('admin.furniture.newgoods.info.view', compact('data'));
  108. }
  109. /**
  110. *
  111. * 状态改变
  112. *
  113. */
  114. public function status(Request $request)
  115. {
  116. $ok = $this->repository->updateStatus(request('id'), request('status'));
  117. if ($ok) {
  118. return $this->showMessage('操作成功');
  119. } else {
  120. return $this->showWarning('操作失败');
  121. }
  122. }
  123. /**
  124. * 删除
  125. */
  126. public function destroy(Request $request)
  127. {
  128. $bool = $this->repository->destroy($request->get('id'));
  129. if ($bool) {
  130. return $this->showMessage('操作成功');
  131. } else {
  132. return $this->showWarning("操作失败");
  133. }
  134. }
  135. /***
  136. * 评价统计
  137. * @param Request $request
  138. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  139. */
  140. public function commentschart(Request $request)
  141. {
  142. $newgoods_id = $request->get('id');
  143. $newgoods = FurnitureNewgoodsInfoModel::find($newgoods_id);
  144. $comments_field_1 = FurnitureNewgoodsCommentModel::where('newgoods_id', $newgoods_id)->select(\DB::raw('AVG(comments_field_1) as field'))->first();
  145. $comments_field_2 = FurnitureNewgoodsCommentModel::where('newgoods_id', $newgoods_id)->select(\DB::raw('AVG(comments_field_2) as field'))->first();
  146. $comments_field_3 = FurnitureNewgoodsCommentModel::where('newgoods_id', $newgoods_id)->select(\DB::raw('AVG(comments_field_3) as field'))->first();
  147. $comments_field_4 = FurnitureNewgoodsCommentModel::where('newgoods_id', $newgoods_id)->select(\DB::raw('AVG(comments_field_4) as field'))->first();
  148. return view('admin.furniture.newgoods.info.commentschart', compact('comments_field_1', 'comments_field_2', 'comments_field_3', 'comments_field_4', 'newgoods'));
  149. }
  150. public function booking(Request $request)
  151. {
  152. $newgoods_id = $request->get('id');
  153. $list = FurnitureNewgoodsBookingModel::where('newgoods_id', $newgoods_id)->orderBy('id', 'desc')->paginate(10);
  154. return view('admin.furniture.newgoods.info.booking', compact('list'));
  155. }
  156. public function bookingremark(Request $request){
  157. $booking = FurnitureNewgoodsBookingModel::find($request->get('id'));
  158. $booking->remark = $request->get('remark');
  159. $bool = $booking->save();
  160. if ($bool) {
  161. return $this->showMessage('操作成功');
  162. } else {
  163. return $this->showWarning("操作失败");
  164. }
  165. }
  166. }