123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php namespace Pinterface\Api;
- use Dever;
- use Pinterface\Lib\Core;
- use Pact\Lib\Core as Act;
- use Porder\Lib\Source\Order as Service;
- use Porder\Lib\Source\Refund;
- class Order extends Core
- {
- protected $login = true;
- protected $entry = true;
- public function init()
- {
- $this->service = Dever::load(Service::class);
- $this->refund = Dever::load(Refund::class);
- }
- # 获取订单列表
- public function list()
- {
- $status = Dever::input('status');
- $data = $this->service->getList($this->place->uid, $status);
- return ['list' => $data];
- }
- # 获取订单详情
- public function info()
- {
- $info = $this->getInfo();
- $info = $this->service->getInfo($info, true);
- $data = ['info' => $info, 'refund_desc_type' => Dever::db('porder/source_refund')->value('desc_type'), 'refund_type' => Dever::db('porder/source_refund')->value('type')];
- if (isset($info['refund']) && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
- $data['refund_delivery'] = [Dever::call("Sector/Lib/Delivery.getList", 1)];
- }
- return $data;
- }
- # 确认收货
- public function finish()
- {
- $info = $this->getInfo();
- $this->service->finish(1, $info);
- return 'ok';
- }
- # 取消订单
- public function cancel()
- {
- $info = $this->getInfo();
- $this->service->cancel($info);
- return 'ok';
- }
- # 再次支付
- public function pay()
- {
- $info = $this->getInfo();
- if ($info['pay_money_cash'] > 0) {
- $result['pay'] = Dever::load(\Place\Lib\Account::class)->pay($info);
- if (isset($result['pay']['link']) && $result['pay']['link']) {
- return $result;
- }
- $result['order_id'] = $info['id'];
- $result['order_num'] = $info['order_num'];
- return $result;
- } else {
- Dever::error('无需支付');
- }
- }
- # 申请退款
- public function refund()
- {
- $info = $this->getInfo();
- /*
- $cash = Dever::input('cash');
- if (!$cash || $cash <= 0) {
- Dever::error('退款金额有误');
- }
- */
- $type = Dever::input('type');
- if (!$type || $type <= 0) {
- Dever::error('退款类型有误');
- }
- $desc_type = Dever::input('desc_type');
- if (!$desc_type || $desc_type <= 0) {
- Dever::error('退款原因有误');
- }
- $desc = Dever::input('desc');
- $this->refund->up([], $info, 1, $this->place->uid, $type, 1, $desc_type, $desc);
- return 'ok';
- }
- # 申请退款发货
- public function refundExpress()
- {
- $info = $this->getInfo();
- $refund_id = Dever::input('refund_id');
- if (!$refund_id) {
- Dever::error('退款信息错误');
- }
- $delivery_id = Dever::input('delivery_id');
- if (!$delivery_id) {
- Dever::error('请选择快递公司');
- }
- $number = Dever::input('number');
- if (!$number) {
- Dever::error('请填写单号');
- }
- $this->refund->express($info, $refund_id, $delivery_id, $number);
- return 'ok';
- }
- # 获取订单信息
- private function getInfo()
- {
- $id = Dever::input('id');
- $order = Dever::input('order');
- if (!$id && !$order) {
- Dever::error('订单信息有误');
- }
- if ($id) {
- $where = ['id' => $id, 'uid' => $this->place->uid];
- } else {
- $where = ['order_num' => $order, 'uid' => $this->place->uid];
- }
- $info = Dever::db('porder/source')->find($where);
- if (!$info) {
- Dever::error('订单信息有误');
- }
- return $info;
- }
- # 提交评价
- public function review_commit(){}
- public function review()
- {
- $info = $this->getInfo();
- if ($info['review_status'] != 2) {
- Dever::error('您现在不可以评价');
- }
- $data['pic'] = Dever::input('pic');
- if (!$data['pic']) {
- $data['pic'] = '';
- }
- $data['content'] = Dever::input('content', 'is_string', '内容');
- $data['rate'] = Dever::input('rate', 'is_numeric', '评分');
- if (!$data['rate']) {
- Dever::error('评分错误');
- }
- $data['rate'] = intval($data['rate']);
- if ($data['rate'] > 5 || $data['rate'] <= 0) {
- Dever::error('评分错误');
- }
- $data['open'] = Dever::input('open');
- if ($data['open'] == 'true') {
- $data['open'] = 1;
- } else {
- $data['open'] = 2;
- }
- $detail = Dever::db('porder/source_detail')->select(['order_id' => $info['id']]);
- foreach ($detail as $v) {
- $act = Act::load('review', $this->place->uid, 1, $v['source_id'])->up($data, '请不要发布相同内容');
- }
- Dever::db('porder/source')->update($info['id'], ['review_status' => 3]);
- return 'ok';
- }
- }
|