Collection.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\order;
  10. use app\admin\service\Service;
  11. use app\admin\model\order\OrderCollection as OrderCollectionModel;
  12. use app\common\models\system\Users as UsersModel;
  13. class Collection extends Service {
  14. /**
  15. * 获取列表数据
  16. * @param $data
  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){
  23. $condition = [];
  24. $key = $data["key"]??[];
  25. $arr = ["order.order_no","users.username"];
  26. if((isset($key["type"]) && isset($arr[$key["type"]])) && !empty($key["title"])){
  27. $condition[] = [$arr[$key["type"]],"like",'%'.$key["title"].'%'];
  28. }
  29. $count = OrderCollectionModel::withJoin(["order","users","payment"])->where($condition)->count();
  30. $result = array_map(function ($res){
  31. $res["username"] = getUserName($res);
  32. return $res;
  33. },OrderCollectionModel::withJoin(["order","users","payment"])->where($condition)->order("id","desc")->page($data["page"]??1,$data["limit"]??10)->select()->toArray());
  34. return ["count"=>$count, "data"=>$result];
  35. }
  36. /**
  37. * 详情
  38. * @param $id
  39. * @return array
  40. * @throws \Exception
  41. */
  42. public static function detail($id){
  43. $data = OrderCollectionModel::alias("c")
  44. ->field('o.order_no,c.user_id,p.name as pname,o.create_time,o.pay_type,u.username,c.amount,o.pay_time,c.admin_id,c.note')
  45. ->join("order o","c.order_id=o.id","LEFT")
  46. ->join("users u","u.id=c.user_id","LEFT")
  47. ->join("payment p","c.payment_id=p.id","LEFT")->where('c.id',$id)->find();
  48. if(empty($data)){
  49. throw new \Exception("您要查找的内容不存在!");
  50. }
  51. $data["username"] = getUserName($data);
  52. $data["pay_time"] = date("Y-m-d H:i:s",$data['pay_time']);
  53. if($data["admin_id"] == "-1"){
  54. $data['admin_name'] = 'system';
  55. }else{
  56. $data['admin_name'] = UsersModel::where(["id"=>$data["admin_id"]])->value("username");
  57. }
  58. return [ "data"=>$data ];
  59. }
  60. }