123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- <?php
- namespace app\admin\controller\unishop;
- use app\admin\model\unishop\Area;
- use app\admin\model\unishop\OrderRefund;
- use app\common\controller\Backend;
- use think\Db;
- use think\Exception;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- use think\Hook;
- use addons\epay\library\Service;
- /**
- * 订单管理
- *
- * @icon fa fa-circle-o
- */
- class Order extends Backend
- {
- /**
- * 是否是关联查询
- */
- protected $relationSearch = true;
- /**
- * Order模型对象
- * @var \app\admin\model\unishop\Order
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\unishop\Order;
- $this->view->assign("payTypeList", $this->model->getPayTypeList());
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("refundStatusList", $this->model->getRefundStatusList());
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->alias('order')
- ->join('user', 'user.id = order.user_id')
- ->where($where)
- ->count();
- $list = $this->model
- ->alias('order')
- ->join('user', 'user.id = order.user_id')
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->field('order.*,user.username')
- ->select();
- $list = collection($list)->toArray();
- foreach ($list as &$item) {
- $item['id'] = (string)$item['id']; // 整形数字太大js会失准
- $item['user'] = [];
- $item['user']['username'] = $item['username'] ? $item['username'] : __('Tourist');
- $item['have_paid_status'] = $item['have_paid'];
- $item['have_delivered_status'] = $item['have_delivered'];
- $item['have_received_status'] = $item['have_received'];
- $item['have_commented_status'] = $item['have_commented'];
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 生成查询所需要的条件,排序方式
- * @param mixed $searchfields 快速查询的字段
- * @param boolean $relationSearch 是否关联查询
- * @return array
- */
- protected function buildparams($searchfields = null, $relationSearch = null)
- {
- $searchfields = is_null($searchfields) ? $this->searchFields : $searchfields;
- $relationSearch = is_null($relationSearch) ? $this->relationSearch : $relationSearch;
- $search = $this->request->get("search", '');
- $filter = $this->request->get("filter", '');
- $op = $this->request->get("op", '', 'trim');
- $sort = $this->request->get("sort", "id");
- $order = $this->request->get("order", "DESC");
- $offset = $this->request->get("offset", 0);
- $limit = $this->request->get("limit", 0);
- $filter = (array)json_decode($filter, true);
- $op = (array)json_decode($op, true);
- $filter = $filter ? $filter : [];
- $where = [];
- $tableName = '';
- if ($relationSearch) {
- if (!empty($this->model)) {
- $name = \think\Loader::parseName(basename(str_replace('\\', '/', get_class($this->model))));
- $tableName = '' . $name . '.';
- }
- $sortArr = explode(',', $sort);
- foreach ($sortArr as $index => & $item) {
- $item = stripos($item, ".") === false ? $tableName . trim($item) : $item;
- }
- unset($item);
- $sort = implode(',', $sortArr);
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- $where[] = [$tableName . $this->dataLimitField, 'in', $adminIds];
- }
- if ($search) {
- $searcharr = is_array($searchfields) ? $searchfields : explode(',', $searchfields);
- foreach ($searcharr as $k => &$v) {
- $v = stripos($v, ".") === false ? $tableName . $v : $v;
- }
- unset($v);
- $where[] = [implode("|", $searcharr), "LIKE", "%{$search}%"];
- }
- foreach ($filter as $k => $v) {
- // 搜索订单状态
- if (in_array($k, ['have_paid_status', 'have_delivered_status', 'have_received_status', 'have_commented_status'])) {
- switch ($k) {
- case 'have_paid_status':
- $k = 'have_paid';
- break;
- case 'have_delivered_status':
- $k = 'have_delivered';
- break;
- case 'have_received_status':
- $k = 'have_received';
- break;
- case 'have_commented_status':
- $k = 'have_commented';
- break;
- }
- $v == 0 ? ($op[$k] = '=') : ($op[$k] = '>');
- $v = 0;
- }
- $sym = isset($op[$k]) ? $op[$k] : '=';
- if (stripos($k, ".") === false) {
- $k = $tableName . $k;
- }
- $v = !is_array($v) ? trim($v) : $v;
- $sym = strtoupper(isset($op[$k]) ? $op[$k] : $sym);
- switch ($sym) {
- case '=':
- case '<>':
- $where[] = [$k, $sym, (string)$v];
- break;
- case 'LIKE':
- case 'NOT LIKE':
- case 'LIKE %...%':
- case 'NOT LIKE %...%':
- $where[] = [$k, trim(str_replace('%...%', '', $sym)), "%{$v}%"];
- break;
- case '>':
- case '>=':
- case '<':
- case '<=':
- $where[] = [$k, $sym, intval($v)];
- break;
- case 'FINDIN':
- case 'FINDINSET':
- case 'FIND_IN_SET':
- $where[] = "FIND_IN_SET('{$v}', " . ($relationSearch ? $k : '`' . str_replace('.', '`.`', $k) . '`') . ")";
- break;
- case 'IN':
- case 'IN(...)':
- case 'NOT IN':
- case 'NOT IN(...)':
- $where[] = [$k, str_replace('(...)', '', $sym), is_array($v) ? $v : explode(',', $v)];
- break;
- case 'BETWEEN':
- case 'NOT BETWEEN':
- $arr = array_slice(explode(',', $v), 0, 2);
- if (stripos($v, ',') === false || !array_filter($arr)) {
- continue 2;
- }
- //当出现一边为空时改变操作符
- if ($arr[0] === '') {
- $sym = $sym == 'BETWEEN' ? '<=' : '>';
- $arr = $arr[1];
- } elseif ($arr[1] === '') {
- $sym = $sym == 'BETWEEN' ? '>=' : '<';
- $arr = $arr[0];
- }
- $where[] = [$k, $sym, $arr];
- break;
- case 'RANGE':
- case 'NOT RANGE':
- $v = str_replace(' - ', ',', $v);
- $arr = array_slice(explode(',', $v), 0, 2);
- if (stripos($v, ',') === false || !array_filter($arr)) {
- continue 2;
- }
- //当出现一边为空时改变操作符
- if ($arr[0] === '') {
- $sym = $sym == 'RANGE' ? '<=' : '>';
- $arr = $arr[1];
- } elseif ($arr[1] === '') {
- $sym = $sym == 'RANGE' ? '>=' : '<';
- $arr = $arr[0];
- }
- $where[] = [$k, str_replace('RANGE', 'BETWEEN', $sym) . ' time', $arr];
- break;
- case 'LIKE':
- case 'LIKE %...%':
- $where[] = [$k, 'LIKE', "%{$v}%"];
- break;
- case 'NULL':
- case 'IS NULL':
- case 'NOT NULL':
- case 'IS NOT NULL':
- $where[] = [$k, strtolower(str_replace('IS ', '', $sym))];
- break;
- default:
- break;
- }
- }
- $where = function ($query) use ($where) {
- foreach ($where as $k => $v) {
- if (is_array($v)) {
- call_user_func_array([$query, 'where'], $v);
- } else {
- $query->where($v);
- }
- }
- };
- return [$where, $sort, $order, $offset, $limit];
- }
- /**
- * 编辑
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException(true)->validate($validate);
- }
- $updatetime = $this->request->post('updatetime');
- // 乐观锁
- $result = $this->model->allowField(true)->save($params, ['id' => $ids, 'updatetime' => $updatetime]);
- if (!$result) {
- throw new Exception(__('Data had been update before saved, close windows and do it again'));
- }
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success();
- } else {
- $this->error(__('No rows were updated'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * 物流管理
- */
- public function delivery($ids = null)
- {
- $row = $this->model->get($ids, ['extend']);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $result = false;
- Db::startTrans();
- try {
- $express_number = $this->request->post('express_number','');
- $express_company = $this->request->post('express_company','');
- // $have_delivered = $express_number ? time() : 0;
- $have_delivered = time();
- $res1 = $row->allowField(true)->save(['have_delivered' => $have_delivered]);
- $res2 = $row->extend->allowField(true)->save(['express_number' => $express_number, 'express_company' => $express_company]);
- if ($res1 !== false && $res2 !== false) {
- $result = true;
- } else {
- throw new Exception(__('No rows were updated'));
- }
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success();
- } else {
- $this->error(__('No rows were updated'));
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $address = json_decode($row->extend->address_json,true);
- if ($address) {
- // $area = (new Area)->whereIn('id',[$address['province_id'],$address['city_id'],$address['area_id']])->column('name', 'id');
- // $row['addressText'] = $area[$address['province_id']].$area[$address['city_id']].$area[$address['area_id']].' '.$address['address'];
- $row['addressText'] = $address['province_name'].$address['city_name'].$address['area_name'].$address['address'];
- $row['address'] = $address;
- }
- $this->view->assign("row", $row);
- // 快递公司
- if (!class_exists(\addons\expressquery\library\Expressquery::class)) {
- $expressInfo = array_merge(['' => '请先安装插件《物流信息接口》']);
- } else {
- $expressInfo = Db::name('expressquery')->column('name', 'express');
- $expressInfo = $expressInfo ?? [];
- $expressInfo = array_merge(['' => '请选择快递公司'], $expressInfo);
- }
- $this->view->assign('expressCompany', $expressInfo);
- return $this->view->fetch();
- }
- /**
- * 商品管理
- */
- public function product($ids = null)
- {
- if ($this->request->isPost()) {
- $this->success();
- }
- $row = $this->model->get($ids, ['product','evaluate','extend']);
- $this->view->assign('product', $row->product);
- $evaluate = [];
- foreach ($row->evaluate as $key => $item) {
- $evaluate[$item['product_id']] = $item;
- }
- //地址
- $row['addressText'] = '';
- $address = json_decode($row->extend->address_json,true);
- if ($address) {
- $row['addressText'] = $address['province_name'].$address['city_name'].$address['area_name'].$address['address'];
- $row['address'] = $address;
- }
- $this->view->assign('order', $row);
- $this->view->assign('evaluate', $evaluate);
- return $this->view->fetch();
- }
- /**
- * 退货管理
- */
- public function refund($ids = null)
- {
- $row = $this->model->get($ids, ['refund']);
- if ($row['status'] != \app\admin\model\unishop\Order::STATUS_REFUND) {
- $this->error(__('This order is not returned'));
- }
- if ($this->request->isPost()) {
- Db::startTrans();
- try {
- $updatetime = $this->request->post('updatetime');
- $refund_amount = $this->request->post('refund_amount');
- $refund_status = $this->request->post('refund_status');
- if ($refund_amount > $row['total_price']) {
- $this->error('退款金额不能大于实际支付金额');
- }
- // 退款
- $params = [
- 'refund_status' => $refund_status,
- 'updatetime' => time(),
- 'refund_amount' => $refund_amount,
- ];
- if($refund_status == 3) {
- $params['had_refund'] = time();
- }
- // 乐观锁
- $result = Db::name('unishop_order')->where(['id' => $ids, 'updatetime' => $updatetime])->update($params);
- if (!$result) {
- throw new Exception(__('Data had been update before saved, close windows and do it again'));
- }
- //修改退款金额
- $rs2 = Db::name('unishop_order_refund')->where('order_id',$ids)->update(['amount'=>$refund_amount]);
- if ($rs2 === false) {
- throw new Exception('操作失败');
- }
- //同意并执行退款
- if($refund_status == 3 && $refund_amount > 0){
- $order = Db::name('unishop_order')->where('id',$ids)->find();
- if($order['pay_type'] == 2){
- $wallet_rs = model('wallet')->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,'商城售后订单退款'.$order['out_trade_no'],'unishop_order',$ids);
- if($wallet_rs['status'] === false){
- throw new Exception($wallet_rs['msg']);
- }
- }elseif($order['pay_type'] == 3 || $order['pay_type'] == 4){
- $refund_result = $this->old_refund($order,$refund_amount);
- if($refund_result !== true){
- throw new Exception($refund_result);
- }
- }
- }
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success();
- }
- $products = $row->product;
- $refundProducts = $row->refundProduct;
- foreach ($products as &$product) {
- $product['choose'] = 0;
- foreach ($refundProducts as $refundProduct) {
- if ($product['id'] == $refundProduct['order_product_id']) {
- $product['choose'] = 1;
- }
- }
- }
- if ($row->refund) {
- $refund = $row->refund->append(['receiving_status_text', 'service_type_text'])->toArray();
- } else {
- $refund = [
- 'service_type' => 0,
- 'express_number' => -1,
- 'receiving_status_text' => -1,
- 'receiving_status' => -1,
- 'service_type_text' => -1,
- 'amount' => -1,
- 'reason_type' => -1,
- 'refund_explain' => -1,
- ];
- }
- $this->view->assign('row', $row);
- $this->view->assign('product', $products);
- $this->view->assign('refund', $refund);
- return $this->view->fetch();
- }
- /**
- * 已支付未发货退款
- */
- public function cancelrefund($ids = null)
- {
- $row = $this->model->get($ids);
- if ($row['status'] != \app\admin\model\unishop\Order::STATUS_CANCEL || $row['have_paid'] == 0 || $row['have_delivered'] != 0) {
- $this->error('订单状态错误');
- }
- if ($this->request->isPost()) {
- Db::startTrans();
- try {
- $updatetime = $this->request->post('updatetime');
- $refund_amount = $this->request->post('refund_amount');
- $refund_status = $this->request->post('refund_status');
- if ($refund_amount > $row['total_price']) {
- $this->error('退款金额不能大于实际支付金额');
- }
- // 退款
- $params = [
- 'refund_status' => $refund_status,
- 'updatetime' => time(),
- 'refund_amount' => $refund_amount,
- ];
- if($refund_status == 3) {
- $params['had_refund'] = time();
- }
- // 乐观锁
- $result = Db::name('unishop_order')->where(['id' => $ids, 'updatetime' => $updatetime])->update($params);
- if (!$result) {
- throw new Exception(__('Data had been update before saved, close windows and do it again'));
- }
- //修改退款金额
- /*$rs2 = Db::name('unishop_order_refund')->where('order_id',$ids)->update(['amount'=>$refund_amount]);
- if ($rs2 === false) {
- throw new Exception('操作失败');
- }*/
- //同意并执行退款
- if($refund_status == 3 && $refund_amount > 0){
- $order = Db::name('unishop_order')->where('id',$ids)->find();
- if($order['pay_type'] == 2){
- $wallet_rs = model('wallet')->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,'商城取消订单退款'.$order['out_trade_no'],'unishop_order',$ids);
- if($wallet_rs['status'] === false){
- throw new Exception($wallet_rs['msg']);
- }
- }elseif($order['pay_type'] == 3 || $order['pay_type'] == 4){
- $refund_result = $this->old_refund($order,$refund_amount);
- if($refund_result !== true){
- throw new Exception($refund_result);
- }
- }
- }
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success();
- }
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- // 退款
- public function old_refund($order, $refund_price)
- {
- $table = 'unishop_order';
- $remark = '订单退款';
- if($order['pay_type'] == 3){
- $order['pay_type'] = 'wechat';
- }
- if($order['pay_type'] == 4){
- $order['pay_type'] = 'alipay';
- }
- // 生成退款单
- $refund_data = [
- 'order_id' => $order['id'],
- 'out_refund_no'=> createUniqueNo('R'),
- 'pay_fee' => $order['total_price'],
- 'refund_price' => $refund_price,
- 'pay_type' => $order['pay_type'],
- 'status' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- 'table' => $table,
- 'table_id' => $order['id'],
- ];
- $refund_log_id = Db::name('pay_order_refund_log')->insertGetId($refund_data);
- if(!$refund_log_id){
- return '退款失败';
- }
- if ($order['pay_type'] == 'wechat' || $order['pay_type'] == 'alipay') {
- // 微信|支付宝退款
- // 退款数据
- $order_data = [
- 'out_trade_no' => $order['pay_out_trade_no']
- ];
- if ($order['pay_type'] == 'wechat') {
- $total_fee = $order['total_price'] * 100;
- $refund_fee = $refund_price * 100;
- $order_data = array_merge($order_data, [
- 'out_refund_no' => $refund_data['out_refund_no'],
- 'total_fee' => $total_fee,
- 'refund_fee' => $refund_fee,
- 'refund_desc' => $remark,
- ]);
- } else {
- $order_data = array_merge($order_data, [
- 'out_request_no' => $refund_data['out_refund_no'],
- 'refund_amount' => $refund_price,
- ]);
- }
- //
- if ($order['pay_type'] == 'wechat') {
- $wxpay = new \app\common\library\Wxpay;
- $result = $wxpay->WxPayRefund($order_data);
- // 微信通知回调 pay->notifyr
- if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
- Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
- return true;
- } else {
- return $result['return_msg'];
- }
- } else {
- $result = Service::submitRefund($order['total_price'],$refund_price,$order['pay_out_trade_no'],$refund_data['out_refund_no'],$order['pay_type'],$remark,'');
- if($result['code'] == '10000'){
- Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
- return true;
- }else{
- return $result['msg'];
- }
- /* return 'alipay wrong way';
- $alipay = new \app\common\library\AliPay;
- $result = $alipay->AliPayRefund($order_data);
- // 支付宝通知回调 pay->notifyx
- return $result;*/
- /*if ($result['code'] == "10000") {
- return true;
- } else {
- throw new \Exception($result['msg']);
- }*/
- }
- // { // 微信返回结果
- // "return_code":"SUCCESS",
- // "return_msg":"OK",
- // "appid":"wx39cd0799d4567dd0",
- // "mch_id":"1481069012",
- // "nonce_str":"huW9eIAb5BDPn0Ma",
- // "sign":"250316740B263FE53F5DFF50AF5A8FA1",
- // "result_code":"SUCCESS",
- // "transaction_id":"4200000497202004072822298902",
- // "out_trade_no":"202010300857029180027000",
- // "out_refund_no":"1586241595",
- // "refund_id":"50300603862020040700031444448",
- // "refund_channel":[],
- // "refund_fee":"1",
- // "coupon_refund_fee":"0",
- // "total_fee":"1",
- // "cash_fee":"1",
- // "coupon_refund_count":"0",
- // "cash_refund_fee":"1
- // }
- // { // 支付宝返回结果
- // "code": "10000",
- // "msg": "Success",
- // "buyer_logon_id": "157***@163.com",
- // "buyer_user_id": "2088902485164146",
- // "fund_change": "Y",
- // "gmt_refund_pay": "2020-08-15 16:11:45",
- // "out_trade_no": "202002460317545607015300",
- // "refund_fee": "0.01",
- // "send_back_fee": "0.00",
- // "trade_no": "2020081522001464141438570535"
- // }
- }
- return true;
- }
- /**
- * 回收站
- */
- public function recyclebin()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->onlyTrashed()
- ->alias('order')
- ->join('user', 'user.id = order.user_id')
- ->where($where)
- ->count();
- $list = $this->model
- ->onlyTrashed()
- ->alias('order')
- ->join('user', 'user.id = order.user_id')
- ->where($where)
- ->field('order.*,user.username')
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $list = collection($list)->toArray();
- foreach ($list as &$item) {
- $item['id'] = (string)$item['id'];
- $item['user'] = [];
- $item['user']['username'] = $item['username'] ? $item['username'] : __('Tourist');
- $item['have_paid_status'] = $item['have_paid'];
- $item['have_delivered_status'] = $item['have_delivered'];
- $item['have_received_status'] = $item['have_received'];
- $item['have_commented_status'] = $item['have_commented'];
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- }
|