GroupOrder.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\products;
  10. use app\admin\service\Service;
  11. use app\admin\model\order\OrderGroup as OrderGroupModel;
  12. class GroupOrder extends Service {
  13. /**
  14. * 获取列表数据
  15. * @param $data
  16. * @param array $condition
  17. * @return array
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\DbException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. */
  22. public static function getList($data,$condition=[]){
  23. $count = OrderGroupModel::withJoin("users")->where($condition)->count();
  24. $result = array_map(function ($res){
  25. $res['people_count'] = OrderGroupModel::where("pid",$res["id"])->count()+1;
  26. $res["username"] = getUserName($res);
  27. return $res;
  28. },OrderGroupModel::withJoin("users")->where($condition)->order("order_group.id","desc")->page($data["page"]??1,$data["limit"]??10)->select()->toArray());
  29. return ["count"=>$count, "data"=>$result];
  30. }
  31. /**
  32. * 详情
  33. * @param $id
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public static function detail($id){
  40. if(!$row = OrderGroupModel::where("id",$id)->find()){
  41. throw new \Exception("您查找的内容不存在!");
  42. }
  43. $row["username"] = getUserName($row);
  44. $row["create_time"] = date("Y-m-d H:i:s",$row["create_time"]);
  45. $row['url'] = createUrl('order.index/detail',['id'=>$row['order_id']]);
  46. $list = OrderGroupModel::withJoin("users")->where("pid",$id)->select()->toArray();
  47. foreach($list as $k=>$v){
  48. $list[$k]['url'] = createUrl('order.index/detail',['id'=>$v['order_id']]);
  49. }
  50. return [ "data"=>array_merge([$row],$list) ];
  51. }
  52. }