Resource.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php namespace Place\Api;
  2. use Dever;
  3. use Place;
  4. use Place\Lib\Main;
  5. use Place\Lib\Cate;
  6. use Place\Lib\Resource as Core;
  7. class Resource extends Main
  8. {
  9. protected $entry = true;
  10. protected $type;
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. $type = Dever::input('type', 'is_numeric', '资源类型');
  15. $this->service = new Core($type);
  16. }
  17. # 首页、列表页
  18. public function home()
  19. {
  20. $cate = new Cate($this->service->app);
  21. $data = $cate->getData();
  22. $data['list'] = $this->service->getList($data['cate_id']);
  23. return Place::result($data);
  24. }
  25. # 详情
  26. public function view()
  27. {
  28. $id = Dever::input('type_id', 'is_numeric', '资源ID');
  29. $data['info'] = $this->service->getInfo($id);
  30. # 分类下其他内容
  31. $data['cate'] = $this->service->getList($data['info']['cate'], $data['info']['id'], 6);
  32. # 最新内容
  33. $data['new'] = $this->service->getList(false, $data['info']['id'], 6);
  34. return Place::result($data);
  35. }
  36. # 点击购买按钮
  37. public function submit()
  38. {
  39. if (!Place::$uid) {
  40. $this->showLogin();
  41. }
  42. $id = Dever::input('type_id', 'is_numeric', '资源ID');
  43. $info = $this->service->getInfo($id);
  44. $data['info'] = Dever::load('info', $this->service->app)->submit($info);
  45. return $data;
  46. }
  47. # 拉起支付
  48. public function pay()
  49. {
  50. if (!Place::$uid) {
  51. $this->showLogin();
  52. }
  53. $id = Dever::input('type_id', 'is_numeric', '资源ID');
  54. $info = $this->service->getInfo($id);
  55. $info = Dever::load('info', $this->service->app)->submit($info, 'price', true);
  56. if ($info['status'] == 2) {
  57. return $this->service->pay($info);
  58. } else {
  59. Dever::error('无权限');
  60. }
  61. }
  62. # 重新支付
  63. public function repay()
  64. {
  65. }
  66. # 资源评论列表
  67. public function getReviewList()
  68. {
  69. $where['type'] = Dever::input('type', 'is_numeric', '类型');
  70. $where['type_id'] = Dever::input('type_id', 'is_numeric', '类型ID');
  71. # 每页10条
  72. $set['num'] = Dever::input('num', 'is_numeric', '分页条数', 3);
  73. $data = Dever::db('review', 'place')->select($where, $set);
  74. if ($data) {
  75. foreach ($data as &$v) {
  76. $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
  77. $v['oper'] = 2;
  78. if (Place::$uid == $v['uid']) {
  79. $v['oper'] = 1;
  80. }
  81. $v['user'] = Dever::db('member', 'place')->find($v['uid'], array('col' => 'mobile,name,avatar'));
  82. }
  83. }
  84. $result['list'] = $data;
  85. $result['total'] = Dever::page('total');
  86. return $result;
  87. }
  88. # 获取订单列表
  89. public function getOrderList()
  90. {
  91. $data['order'][] = array('name' => '待付款', 'status' => 1);
  92. $data['order'][] = array('name' => '待发货', 'status' => 2);
  93. $data['order'][] = array('name' => '待收货', 'status' => '3,4');
  94. $data['order'][] = array('name' => '已完成', 'status' => '5,6,7,9');
  95. $data['order'][] = array('name' => '退款', 'status' => '10');
  96. $data['list'] = $this->service->getOrderList();
  97. return Place::result($data);
  98. }
  99. # 获取订单详情
  100. public function getOrderView()
  101. {
  102. $data['info'] = $this->service->getOrderView();
  103. return Place::result($data);
  104. }
  105. # 修改订单地址
  106. public function upOrderAddress()
  107. {
  108. $this->service->upOrderAddress();
  109. return 'ok';
  110. }
  111. # 确认收货
  112. public function upOrderFinish()
  113. {
  114. $this->service->upOrderFinish();
  115. return 'ok';
  116. }
  117. # 取消订单
  118. public function upOrderCancel()
  119. {
  120. $this->service->upOrderCancel();
  121. return 'ok';
  122. }
  123. # 申请退款
  124. public function applyRefund()
  125. {
  126. $info = $this->service->getOrderView();
  127. if ($info && $info['type'] == 1 && $info['status'] > 1 && $info['status'] < 7 && !$info['refund']) {
  128. $data['type'] = Dever::db('order_refund', $this->service->app)->value('type');
  129. $data['desc_type'] = Dever::db('order_refund', $this->service->app)->value('desc_type');
  130. $data['cash'] = $info['scash'];
  131. $data['detail'] = $info['detail'];
  132. return $data;
  133. } else {
  134. Dever::error('无法申请退款');
  135. }
  136. }
  137. # 确认申请退款
  138. public function applyRefundAct_commit(){}
  139. public function applyRefundAct()
  140. {
  141. $info = $this->service->getOrderView();
  142. if ($info && $info['type'] == 1 && $info['status'] > 1 && $info['status'] < 7 && !$info['refund']) {
  143. $type = Dever::input('apply_type', 'is_numeric', '申请类型');
  144. $desc_type = Dever::input('desc_type', 'is_numeric', '申请原因');
  145. $cash = Dever::input('cash', 'is_numeric', '退款金额');
  146. $desc = Dever::input('desc', 'is_string', '申请说明');
  147. $detail = Dever::input('detail');
  148. if ($detail && is_string($detail)) {
  149. $detail = Dever::json_decode($detail);
  150. }
  151. $log['type'] = 1;
  152. $log['uid'] = Place::$uid;
  153. Dever::load('refund', $this->service->app)->up($detail, $info, $type, $desc_type, $cash, $desc, $log);
  154. return 'ok';
  155. } else {
  156. Dever::error('无法申请退款');
  157. }
  158. }
  159. # 退款单发货 获取信息
  160. public function express()
  161. {
  162. $info = $this->service->getOrderView();
  163. if ($info && $info['type'] == 1 && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
  164. $data['express'] = Dever::db('express', 'sector')->select([]);
  165. return $data;
  166. }
  167. Dever::error('无发货权限');
  168. }
  169. # 退款单发货
  170. public function expressAct()
  171. {
  172. $info = $this->service->getOrderView();
  173. if ($info && $info['type'] == 1 && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
  174. $express_id = Dever::input('express_id', 'is_string', '快递公司');
  175. $number = Dever::input('number', 'is_string', '快递单号');
  176. Dever::load('refund', $this->service->app)->express($info, $info['refund'], $express_id, $number);
  177. return 'ok';
  178. }
  179. Dever::error('无发货权限');
  180. }
  181. }