BigGiftApplyController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\BigGiftApply;
  4. use Carbon\Carbon;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Log;
  9. class BigGiftApplyController extends Controller
  10. {
  11. public function GetApplyList(Request $request)
  12. {
  13. $page_index=$request->input('page_index');
  14. $page_size=$request->input('page_size');
  15. $num=($page_index-1)*$page_size;
  16. $name=Auth::user()->name;
  17. $search_name=$request->input('search_name');
  18. $search_nickname=$request->input('search_nickname');
  19. $search_nicknames=$request->input('search_nicknames');
  20. $status=$request->input('status');
  21. $apply=BigGiftApply::query();
  22. if (Auth::user()->role_id==23){
  23. $apply->where('kefu',$name);
  24. }
  25. if ($search_nickname){
  26. $where=function ($q)use ($search_nickname){
  27. $q->where('name','like',"%$search_nickname%")
  28. ->orwhere('mobile','like',"%$search_nickname%");
  29. };
  30. $apply->where($where);
  31. }
  32. if ($search_nicknames){
  33. $where=function ($q)use ($search_nicknames){
  34. $q->where('nickname','like',"%$search_nicknames%");
  35. };
  36. $apply->where($where);
  37. }
  38. if ($search_name){
  39. $where=function ($q)use ($search_name){
  40. $q->where('c_name','like',"%$search_name%")
  41. ->orwhere('c_mobile','like',"%$search_name%");
  42. };
  43. $apply->where($where);
  44. }
  45. $apply->where('status',$status);
  46. $total=$apply->count();
  47. $list=$apply->skip($num)->take($page_size)->get();
  48. return $this->success_list($list,'',$total);
  49. }
  50. public function Shenhe(Request $request)
  51. {
  52. $id=$request->input('id');
  53. $apply=BigGiftApply::where('id',$id)->first();
  54. if ($request->input('type')==1){
  55. $apply->status=1;
  56. }else{
  57. $apply->status=3;
  58. $apply->reason=$request->input('reason');
  59. }
  60. $apply->save();
  61. return $this->success([]);
  62. }
  63. public function UpdateBigGift(Request $request){
  64. $data=$request->all();
  65. $apply_id=$request->input('id')??null;
  66. DB::beginTransaction();
  67. if (!$apply_id){
  68. return $this->error(50021,'','异常!!');
  69. }
  70. $apply=BigGiftApply::find($apply_id);
  71. try {
  72. //商品详情
  73. $detail=$data['detail'];
  74. $apply->detail=json_encode($detail,true);
  75. //批发商信息
  76. $apply->c_mobile=$data['c_mobile'];
  77. $apply->c_name=$data['c_name'];
  78. //地址信息
  79. $apply->province=$data['province'];
  80. $apply->city=$data['city'];
  81. $apply->area=$data['area'];
  82. $apply->address=$data['address'];
  83. $apply->name=$data['name'];
  84. $apply->mobile=$data['mobile'];
  85. $apply->save();
  86. DB::commit();
  87. return $this->success([]);
  88. }catch (\Exception $exception){
  89. DB::rollBack();
  90. Log::error('提交大礼包申请出错'.$exception->getMessage());
  91. return $this->error(50021,'',$exception->getMessage());
  92. }
  93. }
  94. }