Refundment.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\OrderRefundment as OrderRefundmentModel;
  12. use app\common\models\order\Order as OrderModel;
  13. use app\common\models\order\OrderGoods as OrderGoodsModel;
  14. use app\common\models\system\Users as UsersModel;
  15. use app\common\service\order\Order as OrderService;
  16. class Refundment extends OrderService {
  17. /**
  18. * 查询条件
  19. * @param $key
  20. * @return array
  21. */
  22. protected static function getCondition($key){
  23. $condition = [];
  24. $arr = ["order_refundment.order_no","users.username"];
  25. if((isset($key["type"]) && isset($arr[$key["type"]])) && !empty($key["title"])){
  26. $condition[] = [$arr[$key["type"]],"like",'%'.$key["title"].'%'];
  27. }
  28. if(isset($key["order_status"])){
  29. if(in_array($key["order_status"],[1,2,3,4])){
  30. $condition = [];
  31. switch ($key["order_status"]){
  32. case 1:
  33. $condition[] = ["order_refundment.pay_status","=",0];
  34. break;
  35. case 2:
  36. $condition[] = ["order_refundment.pay_status","=",2];
  37. break;
  38. case 3:
  39. $condition[] = ["order_refundment.pay_status","=",1];
  40. break;
  41. }
  42. }
  43. }
  44. return $condition;
  45. }
  46. /**
  47. * 获取列表数据
  48. * @param $data
  49. * @return array
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public static function getList($data){
  55. $condition = self::getCondition($data["key"]??[]);
  56. $count = OrderRefundmentModel::withJoin(["order","users"])->where($condition)->count();
  57. $result = array_map(function ($res){
  58. $res["username"] = getUserName($res);
  59. $res["refundment_text"] = self::getRefundmentText($res["pay_status"]);
  60. $res["order_url"] = createUrl("order.index/detail",["id"=>$res["order_id"]]);
  61. $res["url"] = createUrl("detail",["id"=>$res["id"]]);
  62. return $res;
  63. },OrderRefundmentModel::withJoin(["order","users"])->where($condition)->order("id","desc")->page($data["page"]??1,$data["limit"]??10)->select()->toArray());
  64. return ["count"=>$count, "data"=>$result];
  65. }
  66. /**
  67. * 详情
  68. * @param $id
  69. * @return array
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public static function detail($id){
  75. $data = OrderRefundmentModel::alias("c")
  76. ->field('o.order_no,o.create_time as order_create_time,u.username,c.*')
  77. ->join("order o","c.order_id=o.id","LEFT")
  78. ->join("users u","u.id=c.user_id","LEFT")->where('c.id',$id)->find();
  79. if(empty($data)){
  80. throw new \Exception("您要查找的内容不存在!");
  81. }
  82. $data["username"] = getUserName($data);
  83. $data["order_create_time"] = date("Y-m-d H:i:s",$data['order_create_time']);
  84. $data["refundment_text"] = self::getRefundmentText($data["pay_status"]);
  85. if($data["admin_id"] == "-1"){
  86. $data['admin_name'] = 'system';
  87. }else{
  88. $data['admin_name'] = UsersModel::where(["id"=>$data["admin_id"]])->value("username");
  89. }
  90. $goods = OrderGoodsModel::where(["order_id" => $data["order_id"]])->order("id","DESC")->select()->toArray();
  91. foreach($goods as $key=>$item){
  92. $goods[$key]["goods_array"] = "";
  93. if(!empty($item["goods_array"])){
  94. $goods[$key]["goods_array"] = json_decode($item["goods_array"],true);
  95. }
  96. $goods[$key]["order_price"] = number_format($item["goods_nums"]*$item["sell_price"],2);
  97. }
  98. $data["goods"] = $goods;
  99. return [ "data"=>$data ];
  100. }
  101. }