| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php namespace Place_order\Lib\Role;
- use Dever;
- class Order
- {
- # 获取订单列表
- public function getList($uid, $status = 0, $sales_type = 0, $sales_id = 0)
- {
- if ($sales_type && $sales_id) {
- $where['sales_type'] = $sales_type;
- $where['sales_id'] = $sales_id;
- } else {
- $where['uid'] = $uid;
- }
- if ($status > 0) {
- if ($status == 1) {
- # 待付款
- $where['status'] = 1;
- } elseif ($status == 2) {
- # 已完成
- $where['status'] = 2;
- } elseif ($status == 3) {
- # 已取消
- $where['status'] = 3;
- }
- }
- $set['num'] = 10;
- $set['col'] = 'id,status,order_num,cdate,score_id,num,cash';
- $data = Dever::db('role', 'place_order')->select($where, $set);
- if ($data) {
- foreach ($data as &$v) {
- $v = $this->getInfo($v);
- }
- }
- return $data;
- }
- # 获取订单信息
- public function getInfo($info, $view = false)
- {
- if ($info['status'] == 1) {
- $m = 3600;
- # 支付倒计时
- $info['time'] = time() - $info['cdate'];
- if ($info['time'] >= $m) {
- # 已过期,自动取消
- $info['time'] = -1;
- $this->cancel($info);
- $info['status'] = 3;
- } else {
- $info['time'] = $m - $info['time'];
- }
- $info['time'] = $info['time'] * 1000;
- }
- $info['score'] = Dever::load('info', 'place_score')->get($info['score_id']);
- $info['detail'] = $this->getDetail($info);
- $info['info'] = '共' . intval($info['num']) . '件';
- $info = $this->getView($info, $view);
- return $info;
- }
- # 获取订单里每个资源
- public function getDetail($info)
- {
- $result = Dever::db('role_detail', 'place_order')->select(['order_id' => $info['id']], ['col' => 'id,cash,status,name,num,role_id,level_id']);
- if ($result) {
- foreach ($result as &$v) {
- $v['cash_text'] = Dever::load('info', 'place_score')->getText($v['cash'], $info['score']);
- $v['status_name'] = Dever::db('role_detail', 'place_order')->value('status', $v['status']);
- }
- }
- return $result;
- }
- # 获取订单详情
- public function getView($info, $view = true)
- {
- if (empty($info['score'])) {
- $info['score'] = Dever::load('info', 'place_score')->get($info['score_id']);
- }
- $info['status_name'] = Dever::db('role', 'place_order')->value('status', $info['status']);
- $info['cash_text'] = Dever::load('info', 'place_score')->getText($info['cash'], $info['score']);
- if (!$view) {
- return $info;
- }
- $this->getViewDate($info);
- list(
- $info['pay_cash_text'],
- $info['wallet_cash_text'],
- $info['coupon_cash_text'],
- $info['gift_cash_text'],
- ) = Dever::load('info', 'place_score')->getText(
- [
- $info['pay_cash'],
- $info['wallet_cash'],
- $info['coupon_cash'],
- $info['gift_cash'],
- ], $info['score']);
- $info['user'] = Dever::db('info', 'place_user')->find($info['uid'], ['col' => 'id,name,mobile,avatar']);
- $info['money'] = Dever::load('info', 'place')->money();
- $info['pay_money_cash_text'] = $info['pay_money_cash'] . $info['money']['unit'];
- return $info;
- }
- # 获取订单详情时间
- public function getViewDate(&$info)
- {
- $info['cdate_str'] = $info['pdate_str'] = '-';
- $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
- if (isset($info['pdate']) && $info['pdate']) {
- $info['pdate_str'] = date('Y-m-d H:i:s', $info['pdate']);
- }
- }
- # 取消订单
- public function cancel($order, $status = 3)
- {
- if ($order['status'] == 1) {
- $state = Dever::db('info', 'place_order')->update($order['id'], ['status' => $status]);
- return 'ok';
- }
- }
- }
|