GoodsorderController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /**
  3. * 商品订单列表
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class GoodsorderController extends AdminbaseController {
  9. protected function getType($k=''){
  10. $type=[
  11. '0'=>'未支付',
  12. '1'=>'支付宝',
  13. '2'=>'微信',
  14. '3'=>'余额',
  15. '4'=>'微信小程序',
  16. '5'=>'Paypal',
  17. '6'=>'BrainTreePaypal',
  18. ];
  19. if($k===''){
  20. return $type;
  21. }
  22. return isset($type[$k]) ? $type[$k]: '';
  23. }
  24. protected function getRefundStatus($k=''){
  25. $mark=[
  26. '-2'=>'买家取消申请',
  27. '-1'=>'失败',
  28. '0'=>'处理中',
  29. '1'=>'成功',
  30. ];
  31. if($k===''){
  32. return $mark;
  33. }
  34. return isset($mark[$k]) ? $mark[$k]: '';
  35. }
  36. protected function getStatus($k=''){
  37. $status=[
  38. '-1'=>'已关闭',
  39. '0'=>'待付款',
  40. '1'=>'待发货',
  41. '2'=>'待收货',
  42. '3'=>'待评价',
  43. '4'=>'已评价',
  44. '5'=>'退款',
  45. ];
  46. if($k===''){
  47. return $status;
  48. }
  49. return isset($status[$k]) ? $status[$k]: '';
  50. }
  51. protected function getDelType($k=''){
  52. $status=[
  53. '-1'=>'买家删除',
  54. '-2'=>'卖家删除',
  55. '1'=>'买家卖家都删除',
  56. '0'=>'未删除',
  57. ];
  58. if($k===''){
  59. return $status;
  60. }
  61. return isset($status[$k]) ? $status[$k]: '';
  62. }
  63. function index(){
  64. $data = $this->request->param();
  65. $map=[];
  66. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  67. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  68. if($start_time!=""){
  69. $map[]=['addtime','>=',strtotime($start_time)];
  70. }
  71. if($end_time!=""){
  72. $map[]=['addtime','<=',strtotime($end_time) + 60*60*24];
  73. }
  74. $orderno=isset($data['orderno']) ? $data['orderno']: '';
  75. if($orderno!=''){
  76. $map[]=['orderno','like','%'.$orderno.'%'];
  77. }
  78. $trade_no=isset($data['trade_no']) ? $data['trade_no']: '';
  79. if($trade_no!=''){
  80. $map[]=['trade_no','like','%'.$trade_no.'%'];
  81. }
  82. $status=isset($data['status']) ? $data['status']: '';
  83. if($status!=''){
  84. $map[]=['status','=',$status];
  85. }
  86. $type=isset($data['type']) ? $data['type']: '';
  87. if($type!=''){
  88. if($type==0){
  89. $map[]=['shop_uid','=',1];
  90. }else{
  91. $map[]=['shop_uid','>',1];
  92. }
  93. }
  94. $share_income=isset($data['share_income']) ? $data['share_income']: '';
  95. if($share_income!=''){
  96. if($share_income==0){
  97. $map[]=['share_income','=',0];
  98. }else{
  99. $map[]=['share_income','>',0];
  100. }
  101. }
  102. $buyer_uid=isset($data['buyer_uid']) ? $data['buyer_uid']: '';
  103. if($buyer_uid!=''){
  104. $map[]=['uid','=',$buyer_uid];
  105. }
  106. $seller_uid=isset($data['seller_uid']) ? $data['seller_uid']: '';
  107. if($seller_uid!=''){
  108. $map[]=['shop_uid','=',$seller_uid];
  109. }
  110. $goods_name=isset($data['goods_name']) ? $data['goods_name']: '';
  111. if($goods_name!=''){
  112. $map[]=['goods_name','like','%'.$goods_name.'%'];
  113. }
  114. $phone=isset($data['phone']) ? $data['phone']: '';
  115. if($phone!=''){
  116. $map[]=['phone','like','%'.$phone.'%'];
  117. }
  118. $lists = Db::name("shop_order")
  119. ->where($map)
  120. ->order("addtime desc")
  121. ->paginate(20);
  122. $lists->each(function($v,$k){
  123. $v['spec_thumb']=get_upload_path($v['spec_thumb']);
  124. $v['buyer_info']=getUserInfo($v['uid']);
  125. $v['seller_info']=getUserInfo($v['shop_uid']);
  126. if($v['shareuid']){
  127. $v['share_info']=getUserInfo($v['shareuid']);
  128. }
  129. return $v;
  130. });
  131. $page = $lists->render();
  132. $this->assign('lists', $lists);
  133. $this->assign("page", $page);
  134. $this->assign("status", $this->getStatus());
  135. $this->assign("type", $this->getType());
  136. $this->assign("refund_status", $this->getRefundStatus());
  137. $this->assign("del_type", $this->getDelType());
  138. return $this->fetch();
  139. }
  140. //获取商品订单详情
  141. public function info(){
  142. $id=$this->request->param('id');
  143. $info=Db::name("shop_order")->where("id={$id}")->find();
  144. if(!$info){
  145. $this->error("商品订单不存在");
  146. }
  147. $info['buyer_info']=getUserInfo($info['uid']);
  148. $info['seller_info']=getUserInfo($info['shop_uid']);
  149. $info['spec_thumb']=get_upload_path($info['spec_thumb']);
  150. $this->assign('data',$info);
  151. $this->assign("status", $this->getStatus());
  152. $this->assign("type", $this->getType());
  153. $this->assign("refund_status", $this->getRefundStatus());
  154. $this->assign("del_type", $this->getDelType());
  155. return $this->fetch();
  156. }
  157. //填写物流信息
  158. public function setexpress(){
  159. $id=$this->request->param("id");
  160. //获取物流公司列表
  161. $key='getExpressList';
  162. $express_list=getcaches($key);
  163. if(!$express_list){
  164. $express_list=DB::name('shop_express')
  165. ->field("id,express_name,express_phone,express_thumb")
  166. ->where('express_status=1')
  167. ->order("list_order asc,id desc")
  168. ->select();
  169. }
  170. $this->assign("orderid",$id);
  171. $this->assign("express_list",$express_list);
  172. return $this->fetch();
  173. }
  174. //填写物流单号提交
  175. public function setexpressPost(){
  176. $data=$this->request->param();
  177. $express_id=$data['express_id'];
  178. $express_number=trim($data['express_number']);
  179. $orderid=trim($data['orderid']);
  180. //获取物流信息
  181. $express_info=Db::name("shop_express")->where("id='{$express_id}'")->find();
  182. if(!$express_info){
  183. $this->error("物流公司不存在");
  184. }
  185. if(!$express_number){
  186. $this->error("请填写物流单号");
  187. }
  188. if (preg_match("/[\x7f-\xff]/", $express_number)) {
  189. $this->error("请确认物流单号是否正确");
  190. }
  191. $now=time();
  192. $data=array(
  193. 'express_name'=>$express_info['express_name'],
  194. 'express_phone'=>$express_info['express_phone'],
  195. 'express_thumb'=>$express_info['express_thumb'],
  196. 'express_code'=>$express_info['express_code'],
  197. 'express_number'=>$express_number,
  198. 'status'=>2,
  199. 'shipment_time'=>$now
  200. );
  201. $res=Db::name("shop_order")->where("id='{$orderid}'")->update($data);
  202. if($res===false){
  203. $this->error("物流信息填写失败");
  204. }
  205. //写入订单消息列表
  206. $orderinfo=getShopOrderInfo(['id'=>$orderid]);
  207. $title="你购买的“".$orderinfo['goods_name']."”商家已经发货,物流单号为:".$express_number;
  208. $data1=array(
  209. 'uid'=>$orderinfo['uid'],
  210. 'orderid'=>$orderid,
  211. 'title'=>$title,
  212. 'addtime'=>$now,
  213. 'type'=>'0'
  214. );
  215. addShopGoodsOrderMessage($data1);
  216. //发送腾讯云IM
  217. txMessageIM($title,$orderinfo['uid'],'goodsorder_admin');
  218. $this->success("物流信息填写成功!",'admin/Goodsorder/index');
  219. //$this->success("物流信息填写成功!");
  220. }
  221. }