Order.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\Admin\controller;
  3. use think\Db;
  4. class Order extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function list()
  11. {
  12. $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
  13. $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
  14. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  15. $where = [];
  16. if ($status !== "") {
  17. $where['a.status'] = $status;
  18. }
  19. $username = isset($this->post['username']) && $this->post['username'] !== "" ? trim($this->post['username']) : "";
  20. if ($username != "") {
  21. $where['e.username'] = ["like", "%{$username}%"];
  22. }
  23. $nickname = isset($this->post['nickname']) && $this->post['nickname'] !== "" ? trim($this->post['nickname']) : "";
  24. if ($nickname != "") {
  25. $where['g.nickname'] = ["like", "%{$nickname}%"];
  26. }
  27. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  28. if ($mobile != "") {
  29. $where['g.mobile'] = ["like", "%{$mobile}%"];
  30. }
  31. $order_low = isset($this->post['order_low']) && $this->post['order_low'] !== "" ? $this->post['order_low'] : "";
  32. if ($order_low != "") {
  33. $order_low = date("Y-m-d H:i:s", strtotime($order_low . " 00:00:00"));
  34. } else {
  35. $order_low = "1970-01-01 00:00:00";
  36. }
  37. $order_up = isset($this->post['order_up']) && $this->post['order_up'] !== "" ? $this->post['order_up'] : "";
  38. if ($order_up != "") {
  39. $order_up = date("Y-m-d H:i:s", strtotime($order_up . " 23:59:59"));
  40. } else {
  41. $order_up = date("Y-m-d H:i:s");
  42. }
  43. $where['a.order_time'] = ["between", [$order_low, $order_up]];
  44. $count = Db::name("order a")->join("fc_order_post b", "a.order_sn=b.order_sn", "left")
  45. ->join("fc_addr c", "b.addrid = c.id", "left")
  46. ->join("fc_account e", "a.accountid = e.id", "left")
  47. ->join("fc_rela_account f", "a.accountid = f.accountid", "left")
  48. ->join("fc_account_info g", "f.account_info =g.id", "left")->where($where)->count();
  49. $total = ceil($count / $size);
  50. $page = $page >= $total ? $total : $page;
  51. $list = Db::name("order a")->where($where)->page($page, $size)->join("fc_order_post b", "a.order_sn=b.order_sn", "left")
  52. ->join("fc_addr c", "b.addrid = c.id", "left")
  53. ->join("fc_account e", "a.accountid = e.id", "left")
  54. ->join("fc_rela_account f", "a.accountid = f.accountid", "left")
  55. ->join("fc_account_info g", "f.account_info =g.id", "left")
  56. ->field("`a`.`id` AS `id`,
  57. `a`.`order_sn` AS `order_sn`,
  58. `a`.`accountid` AS `accountid`,
  59. `a`.`order_num` AS `order_num`,
  60. `a`.`status` AS `status`,
  61. `a`.`is_del` AS `is_del`,
  62. `a`.`delivery_time` AS `delivery_time`,
  63. `a`.`order_time` AS `order_time`,
  64. `b`.`addrid` AS `addrid`,
  65. `b`.`order_num` AS `border_num`,
  66. `b`.`post_code` AS `post_code`,
  67. `b`.`post_name` AS `post_name`,
  68. `b`.`status` AS `bstatus`,
  69. `c`.`addr` AS `addr`,
  70. `c`.`provice` AS `provice`,
  71. `c`.`city` AS `city`,
  72. `c`.`provice_name` AS `provice_name`,
  73. `c`.`city_name` AS `city_name`,
  74. `c`.`area` AS `area`,
  75. `c`.`area_name` AS `area_name`,
  76. `c`.`contector` AS `contector`,
  77. `c`.`mobile` AS `contector_mobile`,
  78. `e`.`username` AS `username`,
  79. `g`.`nickname` AS `nickname`,
  80. `g`.`mobile` AS `mobile`,
  81. `a`.`unit_weight` AS `unit_weight`,
  82. `a`.`unit` AS `unit`
  83. ")
  84. ->order("order_time desc")
  85. ->select();
  86. // var_dump(Db::name("order a")->getLastSql());
  87. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  88. }
  89. /**
  90. * @param ordersn
  91. * @param post_code
  92. * @param post_company
  93. */
  94. public function OrderDelivery()
  95. {
  96. $ordersn = isset($this->post['ordersn']) && $this->post['ordersn'] != "" ? trim($this->post['ordersn']) : "";
  97. if ($ordersn == "") {
  98. return error_show(1004, "参数ordersn 不能为空");
  99. }
  100. $orderinfo = Db::name("order")->where(["order_sn" => $ordersn])->find();
  101. if (empty($orderinfo)) {
  102. return error_show(1005, "订单不存在");
  103. }
  104. if ($orderinfo['is_del'] == 1) {
  105. return error_show(1005, "订单已删除");
  106. }
  107. if ($orderinfo['status'] != 1) {
  108. return error_show(1005, "订单状态有误");
  109. }
  110. $orderpost = Db::name("order_post")->where(["order_sn" => $ordersn, "is_del" => 0])->find();
  111. if (empty($orderpost)) {
  112. return error_show(1005, "订单地址信息不存在");
  113. }
  114. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  115. if ($post_code == "") {
  116. return error_show(1004, "参数post_code 不能为空");
  117. }
  118. $post_company = isset($this->post['post_company']) && $this->post['post_company'] != "" ? trim($this->post['post_company']) : "";
  119. if ($post_company == "") {
  120. return error_show(1004, "参数post_company 不能为空");
  121. }
  122. $orderpost['post_code'] = $post_code;
  123. $orderpost['post_name'] = $post_company;
  124. $orderpost['updatetime'] = date("Y-m-d H:i:s");
  125. Db::startTrans();
  126. try {
  127. $psot = Db::name("order_post")->update($orderpost);
  128. if ($psot) {
  129. $orderinfo['status'] = 2;
  130. $orderinfo['delivery_time'] = date("Y-m-d H:i:s");
  131. $order = Db::name("order")->update($orderinfo);
  132. if ($order) {
  133. write_log("订单{$ordersn}发货", $this->userinfo, "order", "edit", "0");
  134. Db::commit();
  135. return app_show(0, "订单物流信息新建成功");
  136. }
  137. }
  138. Db::rollback();
  139. return error_show(1004, "物流信息新建失败");
  140. } catch (\Exception $e) {
  141. Db::rollback();
  142. return error_show(1004, $e->getMessage());
  143. }
  144. }
  145. public function uploud()
  146. {
  147. $sql = "SELECT
  148. a.order_sn '订单编号',
  149. a.order_num '订单数量',
  150. a.order_time '下单时间',
  151. a.unit_weight '总重量',
  152. if(a.status=1,'待发货',if(a.status=2,'已发货','')) '发货状态',
  153. a.delivery_time '发货时间',
  154. b.post_code '快递编号',
  155. b.post_name '快递公司',
  156. k.username '账户名',
  157. c.addr '收货地址',
  158. c.provice_name '省级名称',
  159. c.city_name '市级名称',
  160. c.area_name '县区名称',
  161. c.contector '收货人',
  162. c.mobile '收货电话',
  163. v.nickname '用户名',
  164. v.mobile AS '用户电话'
  165. FROM
  166. fc_order a
  167. LEFT JOIN fc_order_post b ON b.order_sn = a.order_sn
  168. LEFT JOIN fc_addr c ON c.id = b.addrid
  169. LEFT JOIN fc_account k ON k.id = a.accountid
  170. LEFT JOIN fc_rela_account n ON n.accountid = a.accountid
  171. LEFT JOIN fc_account_info v ON v.id = n.account_info
  172. where a.status=1
  173. ";
  174. $list = Db::query($sql);
  175. if(empty($list)){
  176. $list=[["未找到数据"=>""]];
  177. }
  178. $header = array_keys($list[0]);
  179. array_walk($list, function (&$v) {
  180. $v = array_values($v);
  181. });
  182. excelExport(date("Y-m-d")."未发货订单", $header, $list);
  183. }
  184. }