Order.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php namespace Place_order\Lib\Role;
  2. use Dever;
  3. class Order
  4. {
  5. # 获取订单列表
  6. public function getList($uid, $status = 0, $sales_type = 0, $sales_id = 0)
  7. {
  8. if ($sales_type && $sales_id) {
  9. $where['sales_type'] = $sales_type;
  10. $where['sales_id'] = $sales_id;
  11. } else {
  12. $where['uid'] = $uid;
  13. }
  14. if ($status > 0) {
  15. if ($status == 1) {
  16. # 待付款
  17. $where['status'] = 1;
  18. } elseif ($status == 2) {
  19. # 已完成
  20. $where['status'] = 2;
  21. } elseif ($status == 3) {
  22. # 已取消
  23. $where['status'] = 3;
  24. }
  25. }
  26. $set['num'] = 10;
  27. $set['col'] = 'id,status,order_num,cdate,score_id,num,cash';
  28. $data = Dever::db('role', 'place_order')->select($where, $set);
  29. if ($data) {
  30. foreach ($data as &$v) {
  31. $v = $this->getInfo($v);
  32. }
  33. }
  34. return $data;
  35. }
  36. # 获取订单信息
  37. public function getInfo($info, $view = false)
  38. {
  39. if ($info['status'] == 1) {
  40. $m = 3600;
  41. # 支付倒计时
  42. $info['time'] = time() - $info['cdate'];
  43. if ($info['time'] >= $m) {
  44. # 已过期,自动取消
  45. $info['time'] = -1;
  46. $this->cancel($info);
  47. $info['status'] = 3;
  48. } else {
  49. $info['time'] = $m - $info['time'];
  50. }
  51. $info['time'] = $info['time'] * 1000;
  52. }
  53. $info['score'] = Dever::load('info', 'place_score')->get($info['score_id']);
  54. $info['detail'] = $this->getDetail($info);
  55. $info['info'] = '共' . intval($info['num']) . '件';
  56. $info = $this->getView($info, $view);
  57. return $info;
  58. }
  59. # 获取订单里每个资源
  60. public function getDetail($info)
  61. {
  62. $result = Dever::db('role_detail', 'place_order')->select(['order_id' => $info['id']], ['col' => 'id,cash,status,name,num,role_id,level_id']);
  63. if ($result) {
  64. foreach ($result as &$v) {
  65. $v['cash_text'] = Dever::load('info', 'place_score')->getText($v['cash'], $info['score']);
  66. $v['status_name'] = Dever::db('role_detail', 'place_order')->value('status', $v['status']);
  67. }
  68. }
  69. return $result;
  70. }
  71. # 获取订单详情
  72. public function getView($info, $view = true)
  73. {
  74. if (empty($info['score'])) {
  75. $info['score'] = Dever::load('info', 'place_score')->get($info['score_id']);
  76. }
  77. $info['status_name'] = Dever::db('role', 'place_order')->value('status', $info['status']);
  78. $info['cash_text'] = Dever::load('info', 'place_score')->getText($info['cash'], $info['score']);
  79. if (!$view) {
  80. return $info;
  81. }
  82. $this->getViewDate($info);
  83. list(
  84. $info['pay_cash_text'],
  85. $info['wallet_cash_text'],
  86. $info['coupon_cash_text'],
  87. $info['gift_cash_text'],
  88. ) = Dever::load('info', 'place_score')->getText(
  89. [
  90. $info['pay_cash'],
  91. $info['wallet_cash'],
  92. $info['coupon_cash'],
  93. $info['gift_cash'],
  94. ], $info['score']);
  95. $info['user'] = Dever::db('info', 'place_user')->find($info['uid'], ['col' => 'id,name,mobile,avatar']);
  96. $info['money'] = Dever::load('info', 'place')->money();
  97. $info['pay_money_cash_text'] = $info['pay_money_cash'] . $info['money']['unit'];
  98. return $info;
  99. }
  100. # 获取订单详情时间
  101. public function getViewDate(&$info)
  102. {
  103. $info['cdate_str'] = $info['pdate_str'] = '-';
  104. $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
  105. if (isset($info['pdate']) && $info['pdate']) {
  106. $info['pdate_str'] = date('Y-m-d H:i:s', $info['pdate']);
  107. }
  108. }
  109. # 取消订单
  110. public function cancel($order, $status = 3)
  111. {
  112. if ($order['status'] == 1) {
  113. $state = Dever::db('info', 'place_order')->update($order['id'], ['status' => $status]);
  114. return 'ok';
  115. }
  116. }
  117. }