Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\sub\controller;
  3. use app\common\library\MobileConstant;
  4. use app\common\model\Attachment;
  5. use app\common\model\Mobile;
  6. use app\common\model\MobileOrder;
  7. use app\common\service\MobileOrderExport;
  8. use app\common\service\Refund;
  9. use app\common\service\SmsSend;
  10. use app\common\validate\RefundValidate;
  11. use think\Cookie;
  12. use think\Db;
  13. use think\Hook;
  14. use think\Validate;
  15. /**
  16. * 会员中心
  17. */
  18. class Order extends SubCommon
  19. {
  20. protected $noNeedLogin=[];
  21. protected $noNeedRight=['mobile','index','refund_log','remark'];
  22. public function mobile(){
  23. $data=input();
  24. $model=new Mobile();
  25. if(!empty($data['province_id'])){
  26. $model->where('province_id',$data['province_id']);
  27. }
  28. if(!empty($data['city_id'])){
  29. $model->where('city_id',$data['city_id']);
  30. }
  31. if(!empty($data['network']) && !empty(MobileConstant::getNetwork()[$data['network']]['search'])){
  32. $model->whereIn('network',MobileConstant::getNetwork()[$data['network']]['search']);
  33. }
  34. $list=$model->with(['info'])
  35. ->where('s_id',$this->auth->id)
  36. ->order('id','desc')
  37. ->paginate();
  38. $this->assign('list',$list);
  39. $this->assign('status',$model::$status);
  40. $this->assign('network',MobileConstant::getNetwork());
  41. return view();
  42. }
  43. public function index(){
  44. $data=input();
  45. $page=input('page',1);
  46. $limit=input('limit',15);
  47. $export=input('export');
  48. $model=(new MobileOrder())
  49. ->where('s_id',$this->auth->id);
  50. if(!empty($data['order_no'])){
  51. $model->where('order_no',$data['order_no']);
  52. }
  53. $model
  54. ->with(['info'])
  55. ->order('id','desc');
  56. $extend=[];
  57. if($export){
  58. return MobileOrderExport::export((clone $model)->paginate($limit));
  59. }else{
  60. $extend['total']=(clone $model)->sum('amount');
  61. $extend['alipay']=(clone $model)->where('pay_type',1)->sum('amount');
  62. $extend['wechat']=(clone $model)->where('pay_type',2)->sum('amount');
  63. $extend['jd']=(clone $model)->where('pay_type',3)->sum('amount');
  64. $extend['di']=(clone $model)->sum('amount_di');
  65. $extend['profit']=(clone $model)->sum('amount_profit');
  66. $extend['refund']=(clone $model)->sum('amount_refund');
  67. }
  68. $list=$model->paginate($limit);
  69. $this->assign('list',$list);
  70. $this->assign('extend',$extend);
  71. $this->assign('pay_type',MobileOrder::$payTypes);
  72. $this->assign('status',MobileOrder::$status);
  73. return view();
  74. }
  75. #退款
  76. public function refund(){
  77. $id=input('id',0);
  78. $data=input();
  79. if($this->request->isGet()){
  80. $model=MobileOrder::where('s_id',$this->auth->id)->find($id);
  81. $this->assign('row',$model);
  82. return view();
  83. }else{
  84. $this->validate($data,RefundValidate::class);
  85. Db::startTrans();
  86. $model=MobileOrder::where('s_id',$this->auth->id)->where('id',$id)->lock(true)->findOrFail();
  87. $model->makeRefund('user',$this->auth->getUser(),$data);
  88. Db::commit();
  89. $this->success();
  90. }
  91. }
  92. #退款记录
  93. public function refund_log(){
  94. $id=input('id',0);
  95. $model=MobileOrder::where('s_id',$this->auth->id)->find($id);
  96. $list=$model->refundLog()
  97. ->with(['refunduser'])
  98. ->paginate();
  99. $this->assign('list',$list);
  100. return view();
  101. }
  102. #备注
  103. public function remark(){
  104. $id=input('id',0);
  105. $model=MobileOrder::where('s_id',$this->auth->id)->find($id);
  106. if($this->request->isGet()) {
  107. return view('', compact('model'));
  108. }else{
  109. $remark_sub=input('remark_sub');
  110. $model['remark_sub']=$remark_sub;
  111. $model->save();
  112. $this->success();
  113. }
  114. }
  115. }