Order.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php namespace Pinterface\Api;
  2. use Dever;
  3. use Pinterface\Lib\Core;
  4. use Pact\Lib\Core as Act;
  5. use Porder\Lib\Source\Order as Service;
  6. use Porder\Lib\Source\Refund;
  7. class Order extends Core
  8. {
  9. protected $login = true;
  10. protected $entry = true;
  11. public function init()
  12. {
  13. $this->service = Dever::load(Service::class);
  14. $this->refund = Dever::load(Refund::class);
  15. }
  16. # 获取订单列表
  17. public function list()
  18. {
  19. $status = Dever::input('status');
  20. $data = $this->service->getList($this->place->uid, $status);
  21. return ['list' => $data];
  22. }
  23. # 获取订单详情
  24. public function info()
  25. {
  26. $info = $this->getInfo();
  27. $info = $this->service->getInfo($info, true);
  28. $data = ['info' => $info, 'refund_desc_type' => Dever::db('porder/source_refund')->value('desc_type'), 'refund_type' => Dever::db('porder/source_refund')->value('type')];
  29. if (isset($info['refund']) && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
  30. $data['refund_delivery'] = [Dever::call("Sector/Lib/Delivery.getList", 1)];
  31. }
  32. return $data;
  33. }
  34. # 确认收货
  35. public function finish()
  36. {
  37. $info = $this->getInfo();
  38. $this->service->finish(1, $info);
  39. return 'ok';
  40. }
  41. # 取消订单
  42. public function cancel()
  43. {
  44. $info = $this->getInfo();
  45. $this->service->cancel($info);
  46. return 'ok';
  47. }
  48. # 再次支付
  49. public function pay()
  50. {
  51. $info = $this->getInfo();
  52. if ($info['pay_money_cash'] > 0) {
  53. $result['pay'] = Dever::load(\Place\Lib\Account::class)->pay($info);
  54. if (isset($result['pay']['link']) && $result['pay']['link']) {
  55. return $result;
  56. }
  57. $result['order_id'] = $info['id'];
  58. $result['order_num'] = $info['order_num'];
  59. return $result;
  60. } else {
  61. Dever::error('无需支付');
  62. }
  63. }
  64. # 申请退款
  65. public function refund()
  66. {
  67. $info = $this->getInfo();
  68. /*
  69. $cash = Dever::input('cash');
  70. if (!$cash || $cash <= 0) {
  71. Dever::error('退款金额有误');
  72. }
  73. */
  74. $type = Dever::input('type');
  75. if (!$type || $type <= 0) {
  76. Dever::error('退款类型有误');
  77. }
  78. $desc_type = Dever::input('desc_type');
  79. if (!$desc_type || $desc_type <= 0) {
  80. Dever::error('退款原因有误');
  81. }
  82. $desc = Dever::input('desc');
  83. $this->refund->up([], $info, 1, $this->place->uid, $type, 1, $desc_type, $desc);
  84. return 'ok';
  85. }
  86. # 申请退款发货
  87. public function refundExpress()
  88. {
  89. $info = $this->getInfo();
  90. $refund_id = Dever::input('refund_id');
  91. if (!$refund_id) {
  92. Dever::error('退款信息错误');
  93. }
  94. $delivery_id = Dever::input('delivery_id');
  95. if (!$delivery_id) {
  96. Dever::error('请选择快递公司');
  97. }
  98. $number = Dever::input('number');
  99. if (!$number) {
  100. Dever::error('请填写单号');
  101. }
  102. $this->refund->express($info, $refund_id, $delivery_id, $number);
  103. return 'ok';
  104. }
  105. # 获取订单信息
  106. private function getInfo()
  107. {
  108. $id = Dever::input('id');
  109. $order = Dever::input('order');
  110. if (!$id && !$order) {
  111. Dever::error('订单信息有误');
  112. }
  113. if ($id) {
  114. $where = ['id' => $id, 'uid' => $this->place->uid];
  115. } else {
  116. $where = ['order_num' => $order, 'uid' => $this->place->uid];
  117. }
  118. $info = Dever::db('porder/source')->find($where);
  119. if (!$info) {
  120. Dever::error('订单信息有误');
  121. }
  122. return $info;
  123. }
  124. # 提交评价
  125. public function review_commit(){}
  126. public function review()
  127. {
  128. $info = $this->getInfo();
  129. if ($info['review_status'] != 2) {
  130. Dever::error('您现在不可以评价');
  131. }
  132. $data['pic'] = Dever::input('pic');
  133. if (!$data['pic']) {
  134. $data['pic'] = '';
  135. }
  136. $data['content'] = Dever::input('content', 'is_string', '内容');
  137. $data['rate'] = Dever::input('rate', 'is_numeric', '评分');
  138. if (!$data['rate']) {
  139. Dever::error('评分错误');
  140. }
  141. $data['rate'] = intval($data['rate']);
  142. if ($data['rate'] > 5 || $data['rate'] <= 0) {
  143. Dever::error('评分错误');
  144. }
  145. $data['open'] = Dever::input('open');
  146. if ($data['open'] == 'true') {
  147. $data['open'] = 1;
  148. } else {
  149. $data['open'] = 2;
  150. }
  151. $detail = Dever::db('porder/source_detail')->select(['order_id' => $info['id']]);
  152. foreach ($detail as $v) {
  153. $act = Act::load('review', $this->place->uid, 1, $v['source_id'])->up($data, '请不要发布相同内容');
  154. }
  155. Dever::db('porder/source')->update($info['id'], ['review_status' => 3]);
  156. return 'ok';
  157. }
  158. }