PriceController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * 价格列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-19 16:10:08
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album\Product;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AlbumCatModel;
  12. use App\Models\AlbumProductModel;
  13. use App\Models\AlbumProductPriceModel;
  14. use App\Repositories\Album\Criteria\PriceWhere;
  15. use Illuminate\Http\Request;
  16. use App\Repositories\Base\Criteria\OrderBy;
  17. use App\Repositories\Album\Product\Criteria\MultiWhere;
  18. use App\Repositories\Album\Product\PriceRepository;
  19. class PriceController extends Controller
  20. {
  21. private $repository;
  22. public function __construct(PriceRepository $repository) {
  23. if(!$this->repository) $this->repository = $repository;
  24. }
  25. function index(Request $request) {
  26. $agent_id = $request->input('id');
  27. //dd($agent_id);die;
  28. $search['keyword'] = $request->input('keyword');
  29. $search['cat_id'] = $request->input('cat_id');
  30. $query = $this->repository->pushCriteria(new PriceWhere($search, $this->getStoreId(), $agent_id));
  31. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  32. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  33. }else{
  34. $query = $query->pushCriteria(new OrderBy('id','DESC'));
  35. }
  36. $list = $query->paginate();
  37. foreach ($list as $item){
  38. $product = AlbumProductModel::where([['id',$item->product_id],['store_id',$this->getStoreId()]])->first();
  39. $item->product_name = $product['name'];
  40. $cat = AlbumCatModel::where('id', $product['cat_id'])->first();
  41. $item->product_cat = $cat->name;
  42. $item->product_ma_price_comment = $product['ma_price_comment'];
  43. $item->product_pic = $product['cover_pic'];
  44. }
  45. $cat = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id',0]])->get();
  46. return view('admin.album.product.price.index',compact('list', 'cat'));
  47. }
  48. function check(Request $request) {
  49. $request = $request->all();
  50. $search['keyword'] = $request->input('keyword');
  51. $orderby = array();
  52. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  53. $orderby[$request['sort_field']] = $request['sort_field_by'];
  54. }
  55. $list = $this->repository->search($search,$orderby);
  56. return view('admin.album.product.price.check',compact('list'));
  57. }
  58. /**
  59. * 添加
  60. *
  61. */
  62. public function create(Request $request)
  63. {
  64. if($request->method() == 'POST') {
  65. return $this->_createSave();
  66. }
  67. return view('admin.album.product.price.edit');
  68. }
  69. /**
  70. * 保存修改
  71. */
  72. private function _createSave(){
  73. $data = (array) request('data');
  74. $id = $this->repository->create($data);
  75. if($id) {
  76. $url[] = array('url'=>U( 'Album/Product/Price/index'),'title'=>'返回列表');
  77. $url[] = array('url'=>U( 'Album/Product/Price/create'),'title'=>'继续添加');
  78. $this->showMessage('添加成功',$url);
  79. }else{
  80. $url[] = array('url'=>U( 'Album/Product/Price/index'),'title'=>'返回列表');
  81. return $this->showWarning('添加失败',$url);
  82. }
  83. }
  84. /**
  85. *
  86. * 修改
  87. *
  88. *
  89. */
  90. public function update(Request $request) {
  91. if($request->method() == 'POST') {
  92. return $this->_updateSave();
  93. }
  94. $data = $this->repository->find($request->get('id'));
  95. return view('admin.album.product.price.edit',compact('data'));
  96. }
  97. /**
  98. * 保存修改
  99. */
  100. private function _updateSave() {
  101. $data = (array) request('data');
  102. $ok = $this->repository->update(request('id'),$data);
  103. if($ok) {
  104. $url[] = array('url'=>U( 'Album/Product/Price/index'),'title'=>'返回列表');
  105. return $this->showMessage('操作成功',urldecode(request('_referer')));
  106. }else{
  107. $url[] = array('url'=>U( 'Album/Product/Price/index'),'title'=>'返回列表');
  108. return $this->showWarning('操作失败',$url);
  109. }
  110. }
  111. public function view(Request $request) {
  112. $data = $this->repository->find(request('id'));
  113. return view('admin.album.product.price.view',compact('data'));
  114. }
  115. /**
  116. *
  117. * 状态改变
  118. *
  119. */
  120. public function status(Request $request) {
  121. $ok = $this->repository->updateStatus(request('id'),request('status'));
  122. if($ok) {
  123. return $this->showMessage('操作成功');
  124. }else{
  125. return $this->showWarning('操作失败');
  126. }
  127. }
  128. /**
  129. * 删除
  130. */
  131. public function destroy(Request $request) {
  132. $cat = AlbumProductPriceModel::find($request->get('id'));
  133. $ok = $cat->delete();
  134. if($ok) {
  135. return $this->showMessage('操作成功');
  136. }else{
  137. return $this->showWarning("操作失败");
  138. }
  139. }
  140. }