AgentController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * 经销商管理
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-14 13:26:07
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AgentBannerModel;
  12. use App\Models\AlbumAgentModel;
  13. use App\Models\AlbumProductPriceModel;
  14. use App\Models\AlbumUserModel;
  15. use App\Repositories\Album\Criteria\AgentWhere;
  16. use App\Services\OSS;
  17. use Illuminate\Http\Request;
  18. use App\Repositories\Base\Criteria\OrderBy;
  19. use App\Repositories\Album\Criteria\MultiWhere;
  20. use App\Repositories\Album\AgentRepository;
  21. class AgentController extends Controller
  22. {
  23. private $repository;
  24. public function __construct(AgentRepository $repository) {
  25. if(!$this->repository) $this->repository = $repository;
  26. }
  27. function index(Request $request) {
  28. $search['keyword'] = $request->input('keyword');
  29. $query = $this->repository->pushCriteria(new AgentWhere($search,$this->getStoreId()));
  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. }else{
  33. $query = $query->pushCriteria(new OrderBy('id','DESC'));
  34. }
  35. $list = $query->paginate();
  36. foreach ($list as $item){
  37. $product = AlbumProductPriceModel::where([['agent_id',$item->id],['store_id',$this->getStoreId()]])->first();
  38. if(!empty($product)){
  39. $item->product_name = $product['mobile'];
  40. }
  41. $item->product_pic = $product['cover_pic'];
  42. }
  43. foreach ($list as $item){
  44. if($item->status == 0){
  45. $item->status = '待审核';
  46. }else{
  47. $item->status = '已审核';
  48. }
  49. $user = AlbumUserModel::where('id', $item->user_id)->first();
  50. $item->nickname = $user->username;
  51. $item->role = $user->role;
  52. }
  53. return view('admin.album.agent.index',compact('list'));
  54. }
  55. function check(Request $request) {
  56. $request = $request->all();
  57. $search['keyword'] = $request->input('keyword');
  58. $orderby = array();
  59. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  60. $orderby[$request['sort_field']] = $request['sort_field_by'];
  61. }
  62. $list = $this->repository->search($search,$orderby);
  63. return view('admin.album.agent.check',compact('list'));
  64. }
  65. /**
  66. * 添加
  67. *
  68. */
  69. public function create(Request $request)
  70. {
  71. if($request->method() == 'POST') {
  72. return $this->_createSave();
  73. }
  74. return view('admin.album.agent.edit');
  75. }
  76. /**
  77. * 保存修改
  78. */
  79. private function _createSave(){
  80. $data = (array) request('data');
  81. $id = $this->repository->create($data);
  82. if($id) {
  83. $url[] = array('url'=>U( 'Album/Agent/index'),'title'=>'返回列表');
  84. $url[] = array('url'=>U( 'Album/Agent/create'),'title'=>'继续添加');
  85. $this->showMessage('添加成功',$url);
  86. }else{
  87. $url[] = array('url'=>U( 'Album/Agent/index'),'title'=>'返回列表');
  88. return $this->showWarning('添加失败',$url);
  89. }
  90. }
  91. /**
  92. *
  93. * 修改
  94. *
  95. *
  96. */
  97. public function update(Request $request) {
  98. if($request->method() == 'POST') {
  99. return $this->_updateSave();
  100. }
  101. $data = $this->repository->find($request->get('id'));
  102. return view('admin.album.agent.edit',compact('data'));
  103. }
  104. /**
  105. * 保存修改
  106. */
  107. private function _updateSave() {
  108. $data = (array) request('data');//dd($data);
  109. $ok = $this->repository->update(request('id'),$data);
  110. if($ok) {
  111. $urls[] = array('url'=>U( 'Album/Agent/index'),'title'=>'返回列表');
  112. $this->showMessage('添加成功',$urls);
  113. }else{
  114. $urls[] = array('url'=>U( 'Album/Agent/index'),'title'=>'返回列表');
  115. return $this->showWarning('操作失败',$urls);
  116. }
  117. }
  118. public function view(Request $request) {
  119. $data = $this->repository->find(request('id'));
  120. return view('admin.album.agent.view',compact('data'));
  121. }
  122. /**
  123. *
  124. * 状态改变
  125. *
  126. */
  127. public function status(Request $request) {
  128. $ok = $this->repository->updateStatus(request('id'),request('status'));
  129. if(request('status')==1){
  130. $agent = AlbumAgentModel::find(request('id'));
  131. $user = AlbumUserModel::find($agent->user_id);
  132. $user->is_dealer = 1;
  133. $user->save();
  134. }
  135. if($ok) {
  136. return $this->showMessage('操作成功');
  137. }else{
  138. return $this->showWarning('操作失败');
  139. }
  140. }
  141. /**
  142. * 删除
  143. */
  144. public function destroy(Request $request) {
  145. $agent = AlbumAgentModel::find($request->get('id'));
  146. $id= $agent->user_id;
  147. $ok = $agent->delete();
  148. $save['is_dealer'] = 0;
  149. AlbumUserModel::where('id',$id)->update($save);
  150. if($ok) {
  151. return $this->showMessage('操作成功');
  152. }else{
  153. return $this->showWarning("操作失败");
  154. }
  155. }
  156. }