PriceController.php 4.6 KB

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