BigGiftApplyController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. $status=$request->input('status');
  20. $apply=BigGiftApply::query();
  21. if (Auth::user()->role_id==23){
  22. $apply->where('kefu',$name);
  23. }
  24. if ($search_nickname){
  25. $where=function ($q)use ($search_nickname){
  26. $q->where('name','like',"%$search_nickname%")
  27. ->orwhere('mobile','like',"%$search_nickname%");
  28. };
  29. $apply->where($where);
  30. }
  31. if ($search_name){
  32. $where=function ($q)use ($search_name){
  33. $q->where('c_name','like',"%$search_name%")
  34. ->orwhere('c_mobile','like',"%$search_name%");
  35. };
  36. $apply->where($where);
  37. }
  38. $apply->where('status',$status);
  39. $total=$apply->count();
  40. $list=$apply->skip($num)->take($page_size)->get();
  41. return $this->success_list($list,'',$total);
  42. }
  43. public function Shenhe(Request $request)
  44. {
  45. $id=$request->input('id');
  46. $apply=BigGiftApply::where('id',$id)->first();
  47. if ($request->input('type')==1){
  48. $apply->status=1;
  49. }else{
  50. $apply->status=3;
  51. $apply->reason=$request->input('reason');
  52. }
  53. $apply->save();
  54. return $this->success([]);
  55. }
  56. public function UpdateBigGift(Request $request){
  57. $data=$request->all();
  58. $apply_id=$request->input('id')??null;
  59. DB::beginTransaction();
  60. if (!$apply_id){
  61. return $this->error(50021,'','异常!!');
  62. }
  63. $apply=BigGiftApply::find($apply_id);
  64. try {
  65. //商品详情
  66. $detail=$data['detail'];
  67. $apply->detail=json_encode($detail,true);
  68. //批发商信息
  69. $apply->c_mobile=$data['c_mobile'];
  70. $apply->c_name=$data['c_name'];
  71. //地址信息
  72. $apply->province=$data['province'];
  73. $apply->city=$data['city'];
  74. $apply->area=$data['area'];
  75. $apply->address=$data['address'];
  76. $apply->name=$data['name'];
  77. $apply->mobile=$data['mobile'];
  78. $apply->save();
  79. DB::commit();
  80. return $this->success([]);
  81. }catch (\Exception $exception){
  82. DB::rollBack();
  83. Log::error('提交大礼包申请出错'.$exception->getMessage());
  84. return $this->error(50021,'',$exception->getMessage());
  85. }
  86. }
  87. }