UserController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /**
  3. * 小游戏用户
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-25 10:59:46
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album\Xyx;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AlbumAgentModel;
  12. use Illuminate\Http\Request;
  13. use App\Repositories\Base\Criteria\OrderBy;
  14. use App\Repositories\Album\Xyx\Criteria\MultiWhere;
  15. use App\Repositories\Album\Xyx\UserRepository;
  16. use Illuminate\Support\Facades\DB;
  17. class UserController extends Controller
  18. {
  19. private $repository;
  20. public function __construct(UserRepository $repository) {
  21. if(!$this->repository) $this->repository = $repository;
  22. }
  23. function index(Request $request) {
  24. $search['keyword'] = $request->input('keyword');
  25. $query = $this->repository->pushCriteria(new MultiWhere($search,$this->getStoreId()));
  26. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  27. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  28. }
  29. $list = $query->paginate();
  30. /*$obj1s = DB::table('album_cat')->where([['store_id',1],['parent_id',0]])->get();
  31. $cat_arr = array();
  32. if(!empty($obj1s)){
  33. foreach ($obj1s as $obj1){
  34. $obj1 = get_object_vars($obj1);
  35. $obj1['store_id'] = 2;
  36. $old_cat_id = $obj1['id'];
  37. unset($obj1['id']);
  38. $new_cat_id = DB::table('album_cat')->insertGetId($obj1);
  39. $cat_arr[$old_cat_id] = $new_cat_id;
  40. }
  41. }
  42. $obj2s = DB::table('album_product_style')->where([['store_id',1]])->get();
  43. $style_arr = array();
  44. if(!empty($obj2s)){
  45. foreach ($obj2s as $obj2){
  46. $obj2 = get_object_vars($obj2);
  47. $obj2['store_id'] = 2;
  48. $old_style_id = $obj2['id'];
  49. unset($obj2['id']);
  50. $new_style_id = DB::table('album_product_style')->insertGetId($obj2);
  51. $style_arr[$old_style_id] = $new_style_id;
  52. }
  53. }
  54. $obj3s = DB::table('album_product')->where([['store_id',1]])->get();
  55. if(!empty($obj3s)){
  56. foreach ($obj3s as $obj3){
  57. $obj3 = get_object_vars($obj3);
  58. if(!isset($style_arr[$obj3['style']])||!isset($cat_arr[$obj3['cat_id']])){
  59. continue;
  60. }
  61. $obj3['store_id'] = 2;
  62. $obj3['style'] = $style_arr[$obj3['style']];
  63. $obj3['cat_id'] = $cat_arr[$obj3['cat_id']];
  64. unset($obj3['id']);
  65. DB::table('album_product')->insert($obj3);
  66. }
  67. }
  68. $obj4s = DB::table('album_banner')->where([['store_id',1]])->get();
  69. if(!empty($obj4s)){
  70. foreach ($obj4s as $obj4){
  71. $obj4 = get_object_vars($obj4);
  72. $obj4['store_id'] = 2;
  73. unset($obj4['id']);
  74. DB::table('album_banner')->insert($obj4);
  75. }
  76. }
  77. $obj5s = DB::table('album_manufacturer')->where([['store_id',1]])->get();
  78. if(!empty($obj5s)){
  79. foreach ($obj5s as $obj5){
  80. $obj5 = get_object_vars($obj5);
  81. $obj5['store_id'] = 2;
  82. unset($obj5['id']);
  83. DB::table('album_manufacturer')->insert($obj5);
  84. }
  85. }
  86. $obj6s = DB::table('album_information')->where([['store_id',1]])->get();
  87. if(!empty($obj6s)){
  88. foreach ($obj6s as $obj6){
  89. $obj6 = get_object_vars($obj6);
  90. $obj6['store_id'] = 2;
  91. unset($obj6['id']);
  92. DB::table('album_information')->insert($obj6);
  93. }
  94. }
  95. $obj7s = DB::table('album_news')->where([['store_id',1]])->get();
  96. if(!empty($obj7s)){
  97. foreach ($obj7s as $obj7){
  98. $obj7 = get_object_vars($obj7);
  99. $obj7['store_id'] = 2;
  100. unset($obj7['id']);
  101. DB::table('album_news')->insert($obj7);
  102. }
  103. }
  104. $obj8s = DB::table('album_nav')->where([['store_id',1]])->get();
  105. if(!empty($obj8s)){
  106. foreach ($obj8s as $obj8){
  107. $obj8 = get_object_vars($obj8);
  108. $obj8['store_id'] = 2;
  109. unset($obj8['id']);
  110. DB::table('album_nav')->insert($obj8);
  111. }
  112. }
  113. $obj8s = DB::table('album_info_cat')->where([['store_id',1]])->get();
  114. $info_cat_arr = array();
  115. if(!empty($obj8s)){
  116. foreach ($obj8s as $obj8){
  117. $obj8 = get_object_vars($obj8);
  118. $obj8['store_id'] = 2;
  119. $old_info_cat_id = $obj8['id'];
  120. unset($obj8['id']);
  121. $new_info_cat_id = DB::table('album_info_cat')->insertGetId($obj8);
  122. $info_cat_arr[$old_info_cat_id] = $new_info_cat_id;
  123. }
  124. }
  125. $obj6s = DB::table('album_information')->where([['store_id',1]])->get();
  126. if(!empty($obj6s)){
  127. foreach ($obj6s as $obj6){
  128. $obj6 = get_object_vars($obj6);
  129. if(!isset($info_cat_arr[$obj6['cat_id']])){
  130. continue;
  131. }
  132. $obj6['store_id'] = 2;
  133. $obj6['cat_id'] = $info_cat_arr[$obj6['cat_id']];
  134. unset($obj6['id']);
  135. DB::table('album_information')->insert($obj6);
  136. }
  137. }*/
  138. return view('admin.album.xyx.user.index',compact('list'));
  139. }
  140. function check(Request $request) {
  141. $request = $request->all();
  142. $search['keyword'] = $request->input('keyword');
  143. $orderby = array();
  144. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  145. $orderby[$request['sort_field']] = $request['sort_field_by'];
  146. }
  147. $list = $this->repository->search($search,$orderby);
  148. return view('admin.album.xyx.user.check',compact('list'));
  149. }
  150. /**
  151. * 添加
  152. *
  153. */
  154. public function create(Request $request)
  155. {
  156. if($request->method() == 'POST') {
  157. return $this->_createSave();
  158. }
  159. return view('admin.album.xyx.user.edit');
  160. }
  161. /**
  162. * 保存修改
  163. */
  164. private function _createSave(){
  165. $data = (array) request('data');
  166. $id = $this->repository->create($data);
  167. if($id) {
  168. $url[] = array('url'=>U( 'Album/Xyx/User/index'),'title'=>'返回列表');
  169. $url[] = array('url'=>U( 'Album/Xyx/User/create'),'title'=>'继续添加');
  170. $this->showMessage('添加成功',$url);
  171. }else{
  172. $url[] = array('url'=>U( 'Album/Xyx/User/index'),'title'=>'返回列表');
  173. return $this->showWarning('添加失败',$url);
  174. }
  175. }
  176. /**
  177. *
  178. * 修改
  179. *
  180. *
  181. */
  182. public function update(Request $request) {
  183. /*if($request->method() == 'POST') {
  184. return $this->_updateSave();
  185. }
  186. $data = $this->repository->find($request->get('id'));
  187. return view('admin.album.xyx.user.edit',compact('data'));*/
  188. $data = $this->repository->find($request->get('id'));
  189. if($data->is_dealer == 1){
  190. return $this->showWarning('该用户已成为经销商');
  191. }
  192. $save['is_dealer'] = 1;
  193. $ok = $this->repository->update(request('id'),$save);
  194. if($ok){
  195. $add['store_id'] = $this->getStoreId();
  196. $add['user_id'] = $data->id;
  197. $res = AlbumAgentModel::create($add);
  198. if($res) {
  199. return $this->showMessage('操作成功');
  200. }else{
  201. return $this->showWarning('操作失败');
  202. }
  203. }
  204. return view('admin.album.user.edit',compact('data'));
  205. }
  206. /**
  207. * 保存修改
  208. */
  209. private function _updateSave() {
  210. $data = (array) request('data');
  211. $ok = $this->repository->update(request('id'),$data);
  212. if($ok) {
  213. $url[] = array('url'=>U( 'Album/Xyx/User/index'),'title'=>'返回列表');
  214. return $this->showMessage('操作成功',urldecode(request('_referer')));
  215. }else{
  216. $url[] = array('url'=>U( 'Album/Xyx/User/index'),'title'=>'返回列表');
  217. return $this->showWarning('操作失败',$url);
  218. }
  219. }
  220. public function view(Request $request) {
  221. $data = $this->repository->find(request('id'));
  222. return view('admin.album.xyx.user.view',compact('data'));
  223. }
  224. /**
  225. *
  226. * 状态改变
  227. *
  228. */
  229. public function status(Request $request) {
  230. $ok = $this->repository->updateStatus(request('id'),request('status'));
  231. if($ok) {
  232. return $this->showMessage('操作成功');
  233. }else{
  234. return $this->showWarning('操作失败');
  235. }
  236. }
  237. /**
  238. * 删除
  239. */
  240. public function destroy(Request $request) {
  241. $bool = $this->repository->destroy($request->get('id'));
  242. if($bool) {
  243. return $this->showMessage('操作成功');
  244. }else{
  245. return $this->showWarning("操作失败");
  246. }
  247. }
  248. }