123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- use think\facade\Db;
- class Memberorder extends MobileMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberorder.lang.php');
- }
-
- public function order_list()
- {
- $order_model = model('order');
- $condition = array();
- $condition = $this->order_type_no(input('post.state_type'));
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $condition[] = array('delete_state', '=', 0);
- $order_sn = input('post.order_key');
- if ($order_sn != '') {
- $condition[] = array('order_sn', 'like', '%' . $order_sn . '%');
- }
- $keyword = input('post.keyword');
- if ($keyword != '') {
- $goodscondition = array();
- $goodscondition[] = array('goods_name', 'like', '%' . trim($keyword) . '%');
- $orderidarray = $order_model->getOrdergoodsList($goodscondition, 'order_id');
- $orderidarray = array_column($orderidarray, 'order_id');
- $orderstr = implode(',', $orderidarray);
- $condition[] = array('order_id', 'in', $orderstr);
- }
- $refundreturn_model = model('refundreturn');
- $order_list_array = $order_model->getOrderList($condition, 5, '*', 'order_id desc', 0, array('order_common', 'order_goods', 'store'));
- $order_list_array = $refundreturn_model->getGoodsRefundList($order_list_array, 1);
- $order_group_list = $order_pay_sn_array = array();
- foreach ($order_list_array as $value) {
-
-
- $value['if_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $value);
-
- $value['if_refund_cancel'] = $order_model->getOrderOperateState('refund_cancel', $value);
-
- $value['if_receive'] = $order_model->getOrderOperateState('receive', $value);
-
- $order_info['if_complain'] = $order_model->getOrderOperateState('complain', $value);
-
- $value['if_lock'] = $order_model->getOrderOperateState('lock', $value);
-
- $value['if_deliver'] = $order_model->getOrderOperateState('deliver', $value);
- $value['if_evaluation'] = $order_model->getOrderOperateState('evaluation', $value);
- $value['if_delete'] = $order_model->getOrderOperateState('delete', $value);
- $value['ownshop'] = true;
- $value['zengpin_list'] = false;
- if (isset($value['extend_order_goods'])) {
- foreach ($value['extend_order_goods'] as $val) {
- $val['image_240_url'] = goods_cthumb($val['goods_image'], 240, $val['store_id']);
- $val['image_url'] = goods_cthumb($val['goods_image'], 240, $val['store_id']);
- $val['goods_type_cn'] = get_order_goodstype($val['goods_type']);
- if ($val['goods_type'] == 5) {
- $value['zengpin_list'][] = $val;
- }
- }
- }
-
- if (isset($value['extend_order_goods'])) {
- foreach ($value['extend_order_goods'] as $k => $goods_info) {
- if ($goods_info['goods_type'] == 5) {
- unset($value['extend_order_goods'][$k]);
- } else {
- $value['extend_order_goods'][$k] = $goods_info;
- $value['extend_order_goods'][$k]['goods_image_url'] = goods_cthumb($goods_info['goods_image'], 240, $value['store_id']);
- }
- }
- }
- $order_group_list[$value['pay_sn']]['order_list'][] = $value;
-
- if ($value['order_state'] == ORDER_STATE_NEW || $value['order_state'] == ORDER_STATE_DEPOSIT || $value['order_state'] == ORDER_STATE_REST) {
- if (!isset($order_group_list[$value['pay_sn']]['pay_amount'])) {
- $order_group_list[$value['pay_sn']]['pay_amount'] = 0;
- }
- $order_group_list[$value['pay_sn']]['pay_amount'] += ($value['order_state'] == ORDER_STATE_DEPOSIT ? $value['presell_deposit_amount'] : ($value['order_amount'] - $value['presell_deposit_amount'] + $value['presell_rcb_amount'] + $value['presell_pd_amount'])) - $value['rcb_amount'] - $value['pd_amount'];
- }
- $order_group_list[$value['pay_sn']]['add_time'] = $value['add_time'];
-
- $order_pay_sn_array[] = $value['pay_sn'];
- }
- $new_order_group_list = array();
- foreach ($order_group_list as $key => $value) {
- $value['pay_sn'] = strval($key);
- $new_order_group_list[] = $value;
- }
- $result = array_merge(array('order_group_list' => $new_order_group_list), mobile_page($order_model->page_info));
- ds_json_encode(10000, '', $result);
- }
- private function order_type_no($stage)
- {
- $condition = array();
- switch ($stage) {
- case 'state_new':
- $condition[] = array('order_state', '=', '10');
- break;
- case 'state_pay':
- $condition[] = array('order_state', '=', '20');
- break;
- case 'state_send':
- $condition[] = array('order_state', '=', '30');
- break;
- case 'state_noeval':
- $condition[] = array('order_state', '=', '40');
- $condition[] = array('refund_state', '=', 0);
- $condition[] = array('evaluation_state', '=', '0');
- break;
- }
- return $condition;
- }
-
- public function order_cancel()
- {
- $order_model = model('order');
- $logic_order = model('order', 'logic');
- $order_id = intval(input('post.order_id'));
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
-
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('buyer_cancel', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('have_right_operate'));
- }
- try {
- Db::startTrans();
- $logic_order->changeOrderStateCancel($order_info, 'buyer', $this->member_info['member_name'], lang('other_reason'));
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- Db::commit();
- ds_json_encode(10000, '', 1);
- }
-
- public function order_receive()
- {
- $order_model = model('order');
- $logic_order = model('order', 'logic');
- $order_id = intval(input('post.order_id'));
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('receive', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('have_right_operate'));
- }
- $result = $logic_order->changeOrderStateReceive($order_info, 'buyer', $this->member_info['member_name'], lang('receive_goods'));
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- } else {
- ds_json_encode(10000, '', 1);
- }
- }
-
- public function order_delete()
- {
- $order_model = model('order');
- $logic_order = model('order', 'logic');
- $order_id = intval(input('post.order_id'));
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('delete', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('have_right_operate'));
- }
- $result = $logic_order->changeOrderStateRecycle($order_info, 'buyer', 'delete');
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- } else {
- ds_json_encode(10000, '', 1);
- }
- }
-
- public function search_deliver()
- {
- $order_id = intval(input('post.order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $order_model = model('order');
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
- if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $express = rkcache('express', true);
- if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
- $express_code = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
- $express_name = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
- $deliver_info = $this->_get_express($express_code, $order_info['shipping_code'], $order_info['extend_order_common']['reciver_info']['phone']);
- } else {
- $express_name = '';
- $deliver_info = array();
- }
- ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $order_info['shipping_code'], 'deliver_info' => $deliver_info));
- }
-
- public function order_info()
- {
- $order_id = intval(input('order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $order_info = $order_model->getOrderInfo($condition, array('order_goods', 'order_common', 'store'));
- if (empty($order_info) || $order_info['delete_state'] == ORDER_DEL_STATE_DROP) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $refundreturn_model = model('refundreturn');
- $order_list = array();
- $order_list[$order_id] = $order_info;
- $order_list = $refundreturn_model->getGoodsRefundList($order_list, 1);
- $order_info = $order_list[$order_id];
- $refund_all = isset($order_info['refund_list'][0]) ? $order_info['refund_list'][0] : '';
- if (!empty($refund_all) && $refund_all['seller_state'] < 3) {
- $result['refund_all'] = $refund_all;
- }
- $order_info['store_member_id'] = $order_info['extend_store']['member_id'];
- $order_info['store_phone'] = $order_info['extend_store']['store_phone'];
-
- if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT) {
- $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
- } else if ($order_info['order_state'] == ORDER_STATE_REST) {
- $order_info['order_cancel_day'] = $order_info['presell_end_time'] + 72 * 3600;
- }
- if ($order_info['extend_order_common']['order_message']) {
- $order_info['order_message'] = $order_info['extend_order_common']['order_message'];
- }
- if (!empty($order_info['extend_order_common']['invoice_info'])) {
- $order_info['invoice'] = $order_info['extend_order_common']['invoice_info'];
- }
- $order_info['reciver_phone'] = $order_info['extend_order_common']['reciver_info']['phone'];
- $order_info['reciver_name'] = $order_info['extend_order_common']['reciver_name'];
- $order_info['reciver_addr'] = $order_info['extend_order_common']['reciver_info']['address'];
- $order_info['promotion'] = stripslashes(strip_tags($order_info['extend_order_common']['promotion_info']));
- $order_info['voucher_code'] = $order_info['extend_order_common']['voucher_code'];
- $order_info['voucher_price'] = $order_info['extend_order_common']['voucher_price'];
-
- $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
-
- $order_info['if_buyer_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $order_info);
-
- $order_info['if_refund_cancel'] = $order_model->getOrderOperateState('refund_cancel', $order_info);
-
- $order_info['if_complain'] = $order_model->getOrderOperateState('complain', $order_info);
-
- $order_info['if_receive'] = $order_model->getOrderOperateState('receive', $order_info);
-
- $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
-
- $order_info['if_evaluation'] = $order_model->getOrderOperateState('evaluation', $order_info);
-
- if ($order_info['payment_time']) {
- $order_info['payment_time'] = date('Y-m-d H:i:s', $order_info['payment_time']);
- } else {
- $order_info['payment_time'] = '';
- }
- if ($order_info['finnshed_time']) {
- $order_info['finnshed_time'] = date('Y-m-d H:i:s', $order_info['finnshed_time']);
- } else {
- $order_info['finnshed_time'] = '';
- }
- if ($order_info['add_time']) {
- $order_info['add_time'] = date('Y-m-d H:i:s', $order_info['add_time']);
- } else {
- $order_info['add_time'] = '';
- }
- $order_info['if_deliver'] = false;
-
- if ($order_info['shipping_code'] != '') {
- $order_info['if_deliver'] = true;
- $express = rkcache('express', true);
- if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
- $order_info['express_info']['express_code'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
- $order_info['express_info']['express_name'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
- $order_info['express_info']['express_url'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'];
- } else {
- $order_info['express_info']['express_code'] = '';
- $order_info['express_info']['express_name'] = '';
- $order_info['express_info']['express_url'] = '';
- }
- }
-
- if ($order_info['order_state'] == ORDER_STATE_SEND) {
- $order_info['order_confirm_day'] = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 24 * 3600;
- }
-
- if ($order_info['order_state'] == ORDER_STATE_CANCEL) {
- $close_info = $order_model->getOrderlogInfo(array('order_id' => $order_info['order_id']), 'log_id desc');
- $order_info['close_info'] = $close_info;
-
- $order_info['order_tips'] = $close_info['log_msg'];
- }
- $order_info['chain_order_type'] = 0;
-
- $chain_order_model = model('chain_order');
- $chain_order_info = $chain_order_model->getChainOrderInfo(array(array('order_id', '=', $order_info['order_id'])));
- if ($chain_order_info) {
- $order_info['chain_order_type'] = $chain_order_info['chain_order_type'];
- $order_info['chain_order_pickup_code'] = $chain_order_info['chain_order_pickup_code'];
- $chain_model = model('chain');
- $chain_info = $chain_model->getChainInfo(array(array('chain_id', '=', $chain_order_info['chain_id'])));
- if ($chain_info) {
- $order_info['chain_addressname'] = $chain_info['chain_addressname'];
- $order_info['chain_address'] = $chain_info['chain_address'];
- $phone_list = array();
- if ($chain_info['chain_mobile']) {
- $phone_list[] = $chain_info['chain_mobile'];
- }
- if ($chain_info['chain_telephony']) {
- $phone_list[] = $chain_info['chain_telephony'];
- }
- $order_info['chain_phone'] = implode(',', $phone_list);
- }
- }
- foreach ($order_info['extend_order_goods'] as $value) {
- $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
- $value['image_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
- $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
- if ($value['goods_type'] == 5) {
- $order_info['zengpin_list'][] = $value;
- } else {
- $order_info['goods_list'][] = $value;
- }
- }
- if (empty($order_info['zengpin_list'])) {
- $order_info['goods_count'] = count($order_info['goods_list']);
- } else {
- $order_info['goods_count'] = count($order_info['goods_list']) + 1;
- }
- $order_info['real_pay_amount'] = $order_info['order_amount'] + $order_info['shipping_fee'];
-
-
- $result['order_info'] = $order_info;
- ds_json_encode(10000, '', $result);
- }
-
- public function get_current_deliver()
- {
- $order_id = intval(input('post.order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('buyer_id', '=', $this->member_info['member_id']);
- $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
- if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
- ds_json_encode(10001, lang('member_order_none_exist'));
- }
- $express = rkcache('express', true);
- if (!empty($order_info['extend_order_common']['shipping_express_id'])) {
- $express_code = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
- $express_name = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
- } else {
- $express_code = '';
- $express_name = '';
- }
- $deliver_info = $this->_get_express($express_code, $order_info['shipping_code'], $order_info['extend_order_common']['reciver_info']['phone']);
- $data = array();
- $data['deliver_info']['context'] = $express_name;
- $data['deliver_info']['time'] = $deliver_info['0'];
- ds_json_encode(10000, '', $data);
- }
-
- public function _get_express($express_code, $shipping_code, $phone)
- {
- $result = model('express')->queryExpress($express_code, $shipping_code, $phone);
- if ($result['Success'] != true) {
- ds_json_encode(10001, lang('deliver_search_fail'));
- }
- $content['Traces'] = array_reverse($result['Traces']);
- $output = array();
- if (is_array($content['Traces'])) {
- foreach ($content['Traces'] as $k => $v) {
- if ($v['AcceptTime'] == '')
- continue;
-
- $output[$k]['AcceptTime'] = $v['AcceptTime'];
- $output[$k]['AcceptStation'] = $v['AcceptStation'];
- }
- }
- if (empty($output))
- ds_json_encode(10001, lang('deliver_not_support'));
- return $output;
- }
- }
|