Order.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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\api\service;
  10. use mall\basic\Users;
  11. use mall\library\delivery\aliyun\Aliyun;
  12. use mall\utils\Check;
  13. use think\facade\Db;
  14. use think\facade\Config;
  15. use app\common\models\order\Order as OrderModel;
  16. use app\common\models\order\OrderGoods as OrderGoodsModel;
  17. use app\common\service\order\Order as OrderService;
  18. use mall\utils\Tool;
  19. use app\common\exception\BaseException;
  20. use app\common\models\Area as AreaModel;
  21. use app\common\models\Payment as PaymentModel;
  22. use app\common\models\Store as StoreModel;
  23. use app\common\models\order\OrderRefundment as OrderRefundmentModel;
  24. class Order extends Service {
  25. /**
  26. * 订单列表条件
  27. * @param $type
  28. * @return string
  29. */
  30. public static function getCondition($type){
  31. $condition = 'user_id=' . Users::get("id") . ' and ';
  32. switch($type){
  33. case 1: // 待付款
  34. $condition .= 'status=1 and pay_status=0';
  35. break;
  36. case 2: // 待发货
  37. $condition .= 'status=2 and pay_status=1 and distribution_status=0';
  38. break;
  39. case 3: // 待收货
  40. $condition .= 'status=2 and pay_status=1 and distribution_status in(1,2)';
  41. break;
  42. case 4: // 待评价
  43. $condition .= 'status=5 and pay_status=1 and delivery_status=1 and evaluate_status in(0,2)';
  44. break;
  45. case 5: // 已完成
  46. $condition .= 'status=5 and pay_status=1 and delivery_status=1 and evaluate_status=1';
  47. break;
  48. }
  49. return $condition;
  50. }
  51. /**
  52. * 获取订单列表数据
  53. * @param $data
  54. * @return array
  55. * @throws BaseException
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public static function getList($data){
  61. $size = Config::get("website.pageSize");
  62. $page = $data["page"]??1;
  63. $condition = self::getCondition($data["type"]??1);
  64. $count = OrderModel::where($condition)->count();
  65. $result = OrderModel::where($condition)->order("id","DESC")->page($page,$size)->select()->toArray();
  66. $array = [ "list"=>[], "page"=>$page, "total"=>0, "size"=>$size ];
  67. $total = ceil($count / $size);
  68. $array["total"] = $total;
  69. if($total == $page -1){
  70. throw new BaseException("没有数据了哦!",-1,$array);
  71. }
  72. $list = [];
  73. foreach($result as $key=>$value){
  74. $list[$key] = [
  75. "order_id" => $value["id"],
  76. "shipping" => $value["shipping_type"],
  77. "order_no" => $value["order_no"],
  78. "type" => OrderService::getOrderTypeText($value["type"],1),
  79. "pay_status" => OrderService::getPaymentStatusText($value["pay_status"]),
  80. "order_status" => OrderService::getStatusText(OrderService::getStatus($value)),
  81. "order_amount" => $value["order_amount"],
  82. "create_time" => $value["create_time"],
  83. "active" => OrderService::getStatus($value)
  84. ];
  85. $goods = OrderGoodsModel::where("order_id",$value["id"])->select()->toArray();
  86. foreach($goods as $k=>$v){
  87. $goods_array = json_decode($v["goods_array"],true);
  88. $list[$key]['item'][$k] = [
  89. "title" => $goods_array["title"],
  90. "spec" => $goods_array["spec"],
  91. "thumb_image" => Tool::thumb($v["thumb_image"],"medium",true),
  92. "nums" => $v["goods_nums"],
  93. "price" => $v["sell_price"]
  94. ];
  95. }
  96. }
  97. $array["list"] = $list;
  98. return $array;
  99. }
  100. public static function detail($id){
  101. if(!$order = OrderModel::where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  102. throw new \Exception("您要查找的订单不存在!",0);
  103. }
  104. $order["activity_id"] = $order["activity_id"];
  105. $order["activity_type"] = $order["type"];
  106. $order["active"] = OrderService::getOrderActive($order);
  107. $order["create_time"] = $order["create_time"];
  108. $order["type"] = OrderService::getOrderTypeText($order["type"]);
  109. $order["pay_status"] = OrderService::getPaymentStatusText($order["pay_status"]);
  110. $order["pay_type"] = PaymentModel::where(["id"=>$order["pay_type"]])->value("name");
  111. $order["region"] = AreaModel::getArea([$order['province'],$order['city'],$order['area']],' ');
  112. $order_goods = OrderGoodsModel::where([ "order_id"=>$id ])->select()->toArray();
  113. $fictitiousArray = [];
  114. $orderItem = [];
  115. foreach($order_goods as $key=>$value){
  116. $goods_array = json_decode($value["goods_array"],true);
  117. $fictitious_array = json_decode($value["fictitious_array"],true);
  118. if(!empty($fictitious_array) && in_array($order["status"],["2","5"]) && in_array($order["distribution_status"],[1,2])){
  119. if($fictitious_array["goods_type"] == 1){
  120. $fictitious_array["value"] = $fictitious_array["card"];
  121. }else if($fictitious_array["goods_type"] == 3){
  122. $fictitious_array["value"] = getDomain(). "/" . trim($fictitious_array["value"],"/");
  123. }
  124. $fictitiousArray[] = [
  125. "type" => $fictitious_array["goods_type"],
  126. "title" => $goods_array["title"],
  127. "content" => $fictitious_array["value"]
  128. ];
  129. }
  130. $orderItem[$key] = [
  131. "title" => $goods_array["title"],
  132. "spec" => !empty($goods_array["spec"]) ? $goods_array["spec"] : "",
  133. "goods_id" => $value["goods_id"],
  134. "goods_no" => $value["goods_no"],
  135. "thumb_image" => Tool::thumb($value["thumb_image"],"medium",true),
  136. "sell_price" => $value["sell_price"],
  137. "nums" => $value["goods_nums"]
  138. ];
  139. }
  140. $order["item"] = $orderItem;
  141. $data = [
  142. "activity_id" => $order["activity_id"],
  143. "activity_type" => $order["activity_type"],
  144. "accept_name" => $order["accept_name"],
  145. "mobile" => $order["mobile"],
  146. "region" => $order["region"],
  147. "address" => $order["address"],
  148. "order_no" => $order["order_no"],
  149. "create_time" => $order["create_time"],
  150. "type" => $order["type"],
  151. "pay_status" => $order["pay_status"],
  152. "order_status" => OrderService::getStatus($order),
  153. "pay_type" => $order["pay_type"],
  154. "payable_freight" => Tool::moneyPrefix($order["payable_freight"]),
  155. "order_amount" => Tool::moneyPrefix($order["order_amount"]),
  156. "promotions" => Tool::moneyPrefix($order["promotions"]),
  157. "real_amount" => Tool::moneyPrefix($order["real_amount"]),
  158. "payable_amount" => Tool::moneyPrefix($order["payable_amount"]),
  159. "item" => $order["item"],
  160. "active" => $order["active"],
  161. "users_price" => Users::get("amount"),
  162. "shipping_type" => $order["shipping_type"],
  163. "goods_info" => $fictitiousArray
  164. ];
  165. if($order["shipping_type"] == 2){
  166. $data['qrcode'] = (string)url("qrcode",["data"=>$order["shipping_code"]],false,true);
  167. $array = [];
  168. $array[] = substr($order["shipping_code"],0,4);
  169. $array[] = substr($order["shipping_code"],4,4);
  170. $array[] = substr($order["shipping_code"],8);
  171. $data['code'] = implode(' ',$array);
  172. $store = StoreModel::where("id",$order["store_id"])->find();
  173. $data["area_name"] = AreaModel::getArea([$store["province"],$store["city"],$store["area"]]," ");
  174. $data["shop_name"] = $store["shop_name"];
  175. $data["phone"] = $store["phone"];
  176. $data["shop_address"] = $store["address"];
  177. $data["day_time"] = $store["day_time"];
  178. }
  179. return $data;
  180. }
  181. /**
  182. * 退款
  183. * @param $id
  184. * @return array
  185. * @throws \think\db\exception\DataNotFoundException
  186. * @throws \think\db\exception\DbException
  187. * @throws \think\db\exception\ModelNotFoundException
  188. */
  189. public static function refund($id){
  190. if(!$order = Db::name("order")->where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  191. throw new \Exception("您要查找的订单不存在!",0);
  192. }
  193. if(!in_array($order["status"],[2,6,7])){
  194. throw new \Exception("该订单不允许此操作",0);
  195. }
  196. $order_goods = OrderGoodsModel::where([ "order_id"=>$id ])->select()->toArray();
  197. $refundment = OrderRefundmentModel::where("order_id",$id)->find();
  198. if(!empty($refundment["order_goods_id"])){
  199. $array = explode(",",$refundment["order_goods_id"]);
  200. }else{
  201. $array = [];
  202. }
  203. foreach($order_goods as $key=>$value){
  204. $goods_array = json_decode($value["goods_array"],true);
  205. $order["item"][$key] = [
  206. "title" => $goods_array["title"],
  207. "spec" => !empty($goods_array["spec"]) ? $goods_array["spec"] : "",
  208. "goods_id" => $value["goods_id"],
  209. "goods_no" => $value["goods_no"],
  210. "thumb_image" => Tool::thumb($value["thumb_image"],"medium",true),
  211. "sell_price" => $value["sell_price"],
  212. "nums" => $value["goods_nums"]
  213. ];
  214. $order["item"][$key]["is_refund"] = (!empty($array) && in_array($value["goods_id"],$array)) ? 1 : 0;
  215. }
  216. return [
  217. "payable_freight" => Tool::moneyPrefix($order["payable_freight"]),
  218. "order_amount" => Tool::moneyPrefix($order["order_amount"]),
  219. "promotions" => Tool::moneyPrefix($order["promotions"]),
  220. "real_amount" => Tool::moneyPrefix($order["real_amount"]),
  221. "payable_amount" => Tool::moneyPrefix($order["payable_amount"]),
  222. "is_refund" => !empty($refundment),
  223. "refund_msg" => !empty($refundment["dispose_idea"]) ? $refundment["dispose_idea"] : "",
  224. "order_status" => !empty($refundment) ? $refundment["pay_status"] : '0',
  225. "item" => $order["item"]
  226. ];
  227. }
  228. /**
  229. * 提交退款申请
  230. * @param $params
  231. * @return bool
  232. * @throws \think\db\exception\DataNotFoundException
  233. * @throws \think\db\exception\DbException
  234. * @throws \think\db\exception\ModelNotFoundException
  235. */
  236. public static function applyRefund($params){
  237. $id = intval($params["id"]??0);
  238. $message = strip_tags($params["message"]??"");
  239. if(empty($message)){
  240. throw new \Exception("请填写退款说明",0);
  241. }else if(Check::strlen($message) > 200){
  242. throw new \Exception("退款说明,请控制在200字符内",0);
  243. }
  244. if(!$order = OrderModel::where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  245. throw new \Exception("您要查找的订单不存在!",0);
  246. }
  247. OrderService::refundmentApply($order,$message);
  248. return true;
  249. }
  250. /**
  251. * 确认收货详情
  252. * @param $id
  253. * @return array
  254. * @throws \think\db\exception\DataNotFoundException
  255. * @throws \think\db\exception\DbException
  256. * @throws \think\db\exception\ModelNotFoundException
  257. */
  258. public static function delivery($id){
  259. if(!$order = Db::name("order")->where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  260. throw new \Exception("您要查找的订单不存在!",0);
  261. }
  262. if(!in_array($order["status"],[2,6,7])){
  263. throw new \Exception("该订单不允许此操作",0);
  264. }
  265. $order_goods = OrderGoodsModel::where([ "order_id"=>$id ])->select()->toArray();
  266. foreach($order_goods as $key=>$value){
  267. $goods_array = json_decode($value["goods_array"],true);
  268. $order["item"][$key] = [
  269. "title" => $goods_array["title"],
  270. "spec" => !empty($goods_array["spec"]) ? $goods_array["spec"] : "",
  271. "goods_id" => $value["goods_id"],
  272. "goods_no" => $value["goods_no"],
  273. "thumb_image" => Tool::thumb($value["thumb_image"],"medium",true),
  274. "sell_price" => $value["sell_price"],
  275. "nums" => $value["goods_nums"]
  276. ];
  277. }
  278. return [
  279. "payable_freight" => Tool::moneyPrefix($order["payable_freight"]),
  280. "order_amount" => Tool::moneyPrefix($order["order_amount"]),
  281. "promotions" => Tool::moneyPrefix($order["promotions"]),
  282. "real_amount" => Tool::moneyPrefix($order["real_amount"]),
  283. "payable_amount" => Tool::moneyPrefix($order["payable_amount"]),
  284. "item" => $order["item"]
  285. ];
  286. }
  287. /**
  288. * 确认收货
  289. * @param $id
  290. * @return bool
  291. * @throws \think\db\exception\DataNotFoundException
  292. * @throws \think\db\exception\DbException
  293. * @throws \think\db\exception\ModelNotFoundException
  294. */
  295. public static function confirmDelivery($id){
  296. if(!$order = Db::name("order")->where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  297. throw new \Exception("您要查找的订单不存在!",0);
  298. }
  299. if(!in_array($order["status"],[2,6,7])){
  300. throw new \Exception("该订单不允许此操作",0);
  301. }
  302. try{
  303. Db::startTrans();
  304. Db::name("order")->where(['id'=>$id])->update([ 'status' => 5, 'delivery_status'=>1, 'completion_time' => time() ]);
  305. OrderService::complete($order["order_no"]);
  306. Db::commit();
  307. return true;
  308. }catch (\Exception $ex){
  309. Db::rollback();
  310. throw new \Exception($ex->getMessage(),$ex->getCode());
  311. }
  312. }
  313. /**
  314. * 评价详情
  315. * @param $id
  316. * @return array
  317. * @throws \think\db\exception\DataNotFoundException
  318. * @throws \think\db\exception\DbException
  319. * @throws \think\db\exception\ModelNotFoundException
  320. */
  321. public static function evaluate($id){
  322. if(!$order = Db::name("order")->where([ "user_id"=>Users::get("id"), "id"=>$id ])->find()){
  323. throw new \Exception("您要查找的订单不存在!",0);
  324. }
  325. if($order["status"] != 5){
  326. throw new \Exception("该订单不允许此操作",0);
  327. }else if($order["evaluate_status"] == 1){
  328. throw new \Exception("该订单已评价",2);
  329. }
  330. $order_goods = OrderGoodsModel::where([ "order_id"=>$id ])->select()->toArray();
  331. foreach($order_goods as $key=>$value){
  332. $goods_array = json_decode($value["goods_array"],true);
  333. $order["item"][$key] = [
  334. "title" => $goods_array["title"],
  335. "spec" => !empty($goods_array["spec"]) ? $goods_array["spec"] : "",
  336. "goods_id" => $value["goods_id"],
  337. "goods_no" => $value["goods_no"],
  338. "thumb_image" => Tool::thumb($value["thumb_image"],"medium",true),
  339. "sell_price" => $value["sell_price"],
  340. "nums" => $value["goods_nums"]
  341. ];
  342. }
  343. return [
  344. "payable_freight" => Tool::moneyPrefix($order["payable_freight"]),
  345. "order_amount" => Tool::moneyPrefix($order["order_amount"]),
  346. "promotions" => Tool::moneyPrefix($order["promotions"]),
  347. "real_amount" => Tool::moneyPrefix($order["real_amount"]),
  348. "payable_amount" => Tool::moneyPrefix($order["payable_amount"]),
  349. "item" => $order["item"]
  350. ];
  351. }
  352. /**
  353. * 提交评价
  354. * @param array $params
  355. * @return bool
  356. * @throws \think\db\exception\DataNotFoundException
  357. * @throws \think\db\exception\DbException
  358. * @throws \think\db\exception\ModelNotFoundException
  359. */
  360. public static function applyEvaluate($params=[]){
  361. $id = intval($params["id"]??0);
  362. $message = trim(strip_tags($params["message"]??""));
  363. $rate = intval($params["rate"]??5);
  364. if(!$order = Db::name("order")->where([ "user_id"=>Users::get("id"),"id"=>$id ])->find()){
  365. throw new \Exception("您要查找的订单不存在!",0);
  366. }
  367. if($order["evaluate_status"] == 1){
  368. throw new \Exception("您的订单已评价!",0);
  369. }
  370. try{
  371. Db::startTrans();
  372. $comment = Db::name("users_comment")->where([ "user_id"=>Users::get("id"), "order_no"=>$order["order_no"], "status"=>0 ])->select()->toArray();
  373. foreach($comment as $value){
  374. Db::name("users_comment")->where('id',$value["id"])->update([
  375. "status"=>1,
  376. "contents"=>$message,
  377. "point"=>$rate,
  378. "comment_time"=>time()
  379. ]);
  380. }
  381. Db::name("order")->where([ "user_id"=>Users::get("id"),"id"=>$id ])->update([ "evaluate_status"=>1 ]);
  382. Db::commit();
  383. return true;
  384. }catch (\Exception $ex){
  385. Db::rollback();
  386. throw new \Exception("服务器繁忙,请稍后在试",$ex->getCode());
  387. }
  388. }
  389. /**
  390. * 取消订单
  391. * @param $id
  392. * @return bool
  393. * @throws \think\db\exception\DataNotFoundException
  394. * @throws \think\db\exception\DbException
  395. * @throws \think\db\exception\ModelNotFoundException
  396. */
  397. public static function cancel($id){
  398. $condition = ["user_id"=>Users::get("id"),"id"=>$id];
  399. if(!$order=Db::name("order")->where($condition)->find()){
  400. throw new \Exception("您要操作的订单不存在!",0);
  401. }
  402. if($order["status"] == 1){
  403. Db::name("order")->where($condition)->update([ "status"=>3 ]);
  404. Db::name("order_log")->insert([
  405. 'order_id' => $id,
  406. 'username' => Users::get("username"),
  407. 'action' => "取消订单",
  408. 'result' => '成功',
  409. 'note' => "订单【{$order["order_no"]}】客户取消订单",
  410. 'create_time' => time()
  411. ]);
  412. OrderService::updateOrderGroupStatus($order,3);
  413. return true;
  414. }
  415. if(in_array($order["status"],[3,4])){
  416. throw new \Exception("非法操作",0);
  417. }
  418. throw new \Exception("您的订单已付款,不允许此操作",0);
  419. }
  420. /**
  421. * 售后列表
  422. * @param $data
  423. * @return array
  424. * @throws BaseException
  425. * @throws \think\db\exception\DataNotFoundException
  426. * @throws \think\db\exception\DbException
  427. * @throws \think\db\exception\ModelNotFoundException
  428. */
  429. public static function service($data){
  430. $size = Config::get("website.pageSize");
  431. $page = $data["page"]??1;
  432. $condition = ["r.user_id"=>Users::get("id")];
  433. $count = OrderRefundmentModel::alias("r")->join("order o","r.order_id=o.id","LEFT")->where(["r.user_id"=>Users::get("id")])->count();
  434. $result = OrderRefundmentModel::alias("r")->field("o.*,r.amount,r.pay_status as r_pay_status,r.create_time as r_create_time")->join("order o","r.order_id=o.id","LEFT")->where($condition)->page($page,$size)->select()->toArray();
  435. $array = [ "list"=>[], "page"=>$page, "total"=>0, "size"=>$size ];
  436. $total = ceil($count / $size);
  437. $array["total"] = $total;
  438. if($total == $page -1){
  439. throw new BaseException("没有数据了哦!",-1,$array);
  440. }
  441. $list = [];
  442. foreach($result as $key=>$value){
  443. $list[$key] = [
  444. "order_id" => $value["id"],
  445. "order_no" => $value["order_no"],
  446. "type" => OrderService::getOrderTypeText($value["type"],1),
  447. "pay_status" => OrderService::getRefundmentText($value["r_pay_status"]),
  448. "order_status" => OrderService::getStatusText(OrderService::getStatus($value)),
  449. "order_amount" => $value["order_amount"],
  450. "create_time" => date("Y-m-d H:i:s",$value["r_create_time"]),
  451. "active" => OrderService::getOrderActive($value)
  452. ];
  453. $goods = Db::name("order_goods")->where("order_id",$value["id"])->select()->toArray();
  454. foreach($goods as $k=>$v){
  455. $goods_array = json_decode($v["goods_array"],true);
  456. $list[$key]['item'][$k] = [
  457. "title" => $goods_array["title"],
  458. "spec" => $goods_array["spec"],
  459. "thumb_image" => Tool::thumb($v["thumb_image"],"medium",true),
  460. "nums" => $v["goods_nums"],
  461. "price" => $v["sell_price"]
  462. ];
  463. }
  464. }
  465. $array["list"] = $list;
  466. return $array;
  467. }
  468. /**
  469. * 获取物流信息
  470. * @param $id
  471. * @return array
  472. * @throws \think\db\exception\DataNotFoundException
  473. * @throws \think\db\exception\DbException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. */
  476. public static function getExpressData($id){
  477. if(!$order = Db::name("order")->where(["user_id"=>Users::get("id"),"id"=>$id])->where("distribution_status","in","1,2")->find()){
  478. throw new \Exception("您要查找的订单不存在!",0);
  479. }
  480. $orderDelivery = Db::name("order_delivery")->where("order_id",$id)->find();
  481. if(empty($orderDelivery)){
  482. throw new \Exception("您要查找的订单不存在!",0);
  483. }
  484. $freightData = Db::name("freight")->where("id",$orderDelivery["freight_id"])->find();
  485. $type = strtolower($freightData["type"]);
  486. if($type == 'sfexpress'){
  487. $orderDelivery["distribution_code"] = $orderDelivery["distribution_code"] . ":" . substr($orderDelivery["mobile"],-4);
  488. }
  489. $order["region"] = AreaModel::getArea([$order['province'],$order['city'],$order['area']],' ');
  490. $express = ["expName"=>$freightData["title"]??"", "number"=>$orderDelivery["distribution_code"]??"", "takeTime"=>"", "updateTime"=>""];
  491. try{
  492. $express = Aliyun::query($orderDelivery["distribution_code"],$type);
  493. }catch(\Exception $ex){
  494. $express["list"][] = [
  495. "status" => "商家正在通知快递公司",
  496. "time" => date("Y-m-d H:i:s",$order["send_time"])
  497. ];
  498. }
  499. return [
  500. "accept_name" => $order["accept_name"],
  501. "mobile" => $order["mobile"],
  502. "region" => $order["region"],
  503. "address" => $order["address"],
  504. "order_no" => $order["order_no"],
  505. "express" => $express
  506. ];
  507. }
  508. /**
  509. * 获取订单信息
  510. * @param $id
  511. * @return array
  512. * @throws \think\db\exception\DataNotFoundException
  513. * @throws \think\db\exception\DbException
  514. * @throws \think\db\exception\ModelNotFoundException
  515. */
  516. public static function getOrderInfo($id){
  517. if(!$row=Db::name("order")->where(["id"=>$id,"user_id"=>Users::get("id")])->find()){
  518. throw new \Exception("订单不存在",0);
  519. }
  520. return [
  521. "order_id" => $row["id"],
  522. "order_no" => $row["order_no"],
  523. "create_time" => $row["create_time"],
  524. "order_amount" => number_format($row["order_amount"],2),
  525. "order_status" => OrderService::getPaymentStatusText($row["pay_status"]),
  526. "payment_type" => PaymentModel::where("id",$row["pay_type"])->value("name"),
  527. "users_price" => Db::name("users")->where("id",Users::get("id"))->value("amount")
  528. ];
  529. }
  530. }