Order.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace app\shop\controller;
  3. use app\common\controller\Frontend;
  4. use think\Session;
  5. class Order extends Frontend
  6. {
  7. protected $noNeedLogin = [''];
  8. protected $noNeedRight = '*';
  9. protected $layout = '';
  10. public function index()
  11. {
  12. $addressid=input('addressid');
  13. if(empty($addressid))
  14. {
  15. #地址
  16. $address=db('user_address')->where(['userid'=>$this->auth->id])->order('isdefault desc')->find();
  17. if(empty($address))
  18. {
  19. $address=[];
  20. }
  21. }else{
  22. #地址
  23. $address=db('user_address')->where(['id'=>$addressid])->order('isdefault desc')->find();
  24. if(empty($address))
  25. {
  26. $address=[];
  27. }
  28. }
  29. #商品
  30. $goods=db('goods_cart')->where(['userid'=>$this->auth->id,'isselected'=>1])->select();
  31. if(empty($goods))
  32. {
  33. return $this->fetch('emptysubmit');
  34. }
  35. $proids=db('goods_cart')->where(['userid'=>$this->auth->id,'isselected'=>1])->column('goodsid');
  36. $goodsmoney=db('goods_cart')->where(['userid'=>$this->auth->id,'isselected'=>1])->sum('price');
  37. $delivery=db('goods')->where(['id'=>['in',$proids]])->sum('delivery');
  38. $this->view->assign([
  39. 'goods'=>$goods,
  40. 'address'=>$address,
  41. 'delivery'=>$delivery,
  42. 'total'=>$delivery+$goodsmoney,
  43. ]);
  44. return $this->fetch();
  45. }
  46. function addresslist()
  47. {
  48. $type=input('type');
  49. if(empty($type))
  50. {
  51. $type=0;
  52. }
  53. $this->view->assign("type",$type);
  54. $list=db('user_address')->where(['userid'=>$this->auth->id])->select();
  55. $this->view->assign("list",$list);
  56. return $this->fetch();
  57. }
  58. function addressadd()
  59. {
  60. $type=input('type');
  61. if(empty($type))
  62. {
  63. $type=0;
  64. }
  65. $this->view->assign("type",$type);
  66. return $this->fetch();
  67. }
  68. function addressedit()
  69. {
  70. $id=input('id');
  71. $type=input('type');
  72. if(empty($type))
  73. {
  74. $type=0;
  75. }
  76. $this->view->assign("type",$type);
  77. $info=db('user_address')->where(['id'=>$id])->find();
  78. $this->view->assign("info",$info);
  79. return $this->fetch();
  80. }
  81. function orddetailed()
  82. {
  83. $orderid=input('orderid');
  84. $orderinfo=db('order')->where(['id'=>$orderid])->find();
  85. if($orderinfo['orderStatus'] == 1)
  86. {
  87. if($orderinfo['isrefund'] == 1)
  88. {
  89. $orderinfo['status']='退款中';
  90. }else{
  91. $orderinfo['status']='待发货';
  92. }
  93. }else{
  94. $orderinfo['status']=config('orderStatus')[$orderinfo['orderStatus']];
  95. }
  96. $this->view->assign("info",$orderinfo);
  97. $ordGoods=db('order_goods')->where(['orderid'=>$orderid])->select();
  98. $this->view->assign("ordGoods",$ordGoods);
  99. return $this->fetch();
  100. }
  101. function pay()
  102. {
  103. $goodsid=input('goodsid');
  104. $goodsinfo=db('goods')->where(['id'=>$goodsid])->find();
  105. $trade=db('trade')->where(['status'=>4,'goodsid'=>$goodsid])->order('id desc')->find();
  106. if($trade)
  107. {
  108. $goodsinfo['price']=$trade['nums']*(1+$goodsinfo['radio']*0.01);
  109. }
  110. $feeconfig=db('bonus_config')->where(['config_type'=>3])->find();
  111. $pingtaibi=db('bonus_config')->where(['config_type'=>5,'user_level'=>$goodsinfo['catid']])->find();
  112. $total=$pingtaibi['value']+$feeconfig['value']*0.01* $goodsinfo['price'];
  113. $suser=get_user_data($goodsinfo['userid']);
  114. $this->view->assign([
  115. "goods"=>$goodsinfo,
  116. 'selluser'=>$suser,
  117. 'totalfee'=>$total
  118. ]);
  119. return $this->fetch('index');
  120. }
  121. function topay()
  122. {
  123. $orderid=input('orderid');
  124. $orderinfo=db('order')->where(['id'=>$orderid,'orderStatus' => -2])->find();
  125. if(empty($orderinfo))
  126. {
  127. $this->error('订单不存在或状态已改变');
  128. }
  129. $type=input('type');
  130. if($type != 1 && $type != 2)
  131. {
  132. $this->error('支付类型有误');
  133. }
  134. if($type == 1)
  135. {
  136. $payType=11;
  137. }else{
  138. $payType=21;
  139. }
  140. $merchant=config('site')['merchant'];
  141. if(empty($merchant))
  142. {
  143. $this->error('请前往后台设置商户号');
  144. }
  145. $key=config('site')['paykey'];
  146. if(empty($key))
  147. {
  148. $this->error('请前往后台设置支付密钥');
  149. }
  150. $data = [
  151. "orderAmount"=>$orderinfo['needPay'], //金额
  152. "orderId"=>$orderinfo['orderNo'],//订单号
  153. "merchant"=>$merchant, //商户号
  154. 'method'=>$type,
  155. "type"=>$payType,
  156. "out"=>"no",
  157. ];
  158. ksort($data);//函数对关联数组按照键名进行升序排序。
  159. $postString = http_build_query($data);//返回一个 URL 编码后的字符串。
  160. $signMyself = strtoupper(md5($postString.$key));
  161. $data["sign"] = $signMyself;
  162. $data['createTime'] = time();
  163. $data['returnUrl'] = 'http://' . $_SERVER['HTTP_HOST'] .'/shop/order/orderlist';
  164. $data['notifyUrl'] = 'http://' . $_SERVER['HTTP_HOST'] .'/api/shop/notify';
  165. $postString = http_build_query($data);
  166. $url="http://47.104.25.167/index.php/Api/Index/index?".$postString;
  167. header('Location:'.$url);
  168. }
  169. /* 退款 */
  170. function refund()
  171. {
  172. $orderid=input('orderid');
  173. $this->view->assign("orderid",$orderid);
  174. return $this->fetch();
  175. }
  176. function appraise()
  177. {
  178. $orderid=input('orderid');
  179. $ordGoods=db('order_goods')->where(['orderid'=>$orderid])->select();
  180. $this->view->assign("ordGoods",$ordGoods);
  181. return $this->fetch();
  182. }
  183. /* 订单列表 */
  184. function orderlist()
  185. {
  186. return $this->fetch();
  187. }
  188. function orderlist1()
  189. {
  190. return $this->fetch();
  191. }
  192. function orderlist2()
  193. {
  194. return $this->fetch();
  195. }
  196. function orderlist3()
  197. {
  198. return $this->fetch();
  199. }
  200. function orderlist4()
  201. {
  202. return $this->fetch();
  203. }
  204. }