123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- use think\facade\Db;
- class Sellerorder extends MobileSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerorder.lang.php');
- }
-
- public function order_list()
- {
- $order_model = model('order');
- $condition = array();
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $order_sn = input('post.order_sn');
- if (!empty($order_sn)) {
- $condition[] = array('order_sn', '=', $order_sn);
- }
- $buyer_name = input('post.buyer_name');
- $pagesize = intval('pagesize');
- if (!empty($buyer_name)) {
- $condition[] = array('buyer_name', '=', $buyer_name);
- }
- $allow_state_array = array('state_new', 'state_pay', 'state_send', 'state_success', 'state_cancel');
- $state_type = input('post.state_type');
- if (in_array($state_type, $allow_state_array)) {
- $condition[] = array('order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
- }
- $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
- $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
- $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
- $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
- if ($start_unixtime || $end_unixtime) {
- $condition[] = array('add_time', 'between', array($start_unixtime, $end_unixtime));
- }
- $skip_off = input('param.buyer_name');
- if ($skip_off == 1) {
- $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
- }
- $order_list = $order_model->getOrderList($condition, (($pagesize < 1) ? 10 : $pagesize), '*', 'order_id desc', '', array('order_goods', 'order_common', 'ppintuanorder', 'member'));
- $mobile_page = $order_model->page_info;
-
- foreach ($order_list as $key => $order_info) {
-
- $order_info['if_cancel'] = $order_model->getOrderOperateState('store_cancel', $order_info);
-
- $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
-
- $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
-
- $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
-
- $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
-
- $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
- foreach ($order_info['extend_order_goods'] as $value) {
- $value['image_240_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_list[$key] = $order_info;
- }
- $order_list = array_values($order_list);
- $result = array_merge(array('order_list' => $order_list), mobile_page($mobile_page));
- ds_json_encode(10000, '', $result);
- }
-
- public function search_deliver()
- {
- $order_id = intval(input('post.order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('store_order_none_existr'));
- }
- $condition = array();
- $order_model = model('order');
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_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('store_order_none_existr'));
- }
- $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 _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_exist'));
- return $output;
- }
-
- public function get_current_deliver()
- {
- $order_id = intval(input('post.order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('store_order_none_existr'));
- }
- $condition = array();
- $order_model = model('order');
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_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('store_order_none_existr'));
- }
- $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_code = '';
- $express_name = '';
- $deliver_info = array('0' => '');
- }
- $data = array();
- $data['deliver_info']['context'] = $express_name;
- $data['deliver_info']['time'] = $deliver_info['0'];
- ds_json_encode(10000, '', $data);
- }
-
- public function order_info()
- {
- $order_id = intval(input('param.order_id'));
- if (!$order_id) {
- ds_json_encode(10001, lang('param_error'));
- }
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods', 'member'));
- if (empty($order_info)) {
- ds_json_encode(10001, lang('store_order_none_existr'));
- }
- $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) {
- $order_info['extend_refund']['refund_all'] = $refund_all;
- }
- 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'] = '';
- }
- 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['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
-
- $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
-
- $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
-
- $order_info['if_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $order_info);
-
- $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
-
- $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
-
- if ($order_info['order_state'] == ORDER_STATE_NEW) {
- $order_info['order_cancel_day'] = date('Y-m-d H:i:s', strtotime($order_info['add_time']) + config('ds_config.order_auto_cancel_day') * 24 * 3600);
- }
-
- if ($order_info['shipping_code'] != '') {
- $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;
- }
-
- $order_log_list = $order_model->getOrderlogList(array('order_id' => $order_info['order_id']), 'log_id asc');
- $order_info['extend_log']['order_log_list'] = $order_log_list;
-
- if ($order_info['order_state'] == ORDER_STATE_CANCEL) {
- $last_log = end($order_log_list);
- if ($last_log['log_orderstate'] == ORDER_STATE_CANCEL) {
- $order_info['close_info'] = $last_log;
- }
- }
- $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'];
- }
- foreach ($order_info['extend_order_goods'] as $value) {
- $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
- $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
- $order_info['zengpin_list'] = array();
- 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['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'];
-
- if (!empty($order_info['extend_order_common']['daddress_id'])) {
- $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
- $order_info['daddress_info'] = $daddress_info;
- }
- $order_info['real_pay_amount'] = $order_info['order_amount'] + $order_info['shipping_fee'];
- ds_json_encode(10000, '', array('order_info' => $order_info));
- }
-
- public function order_cancel()
- {
- $order_id = intval(input('post.order_id'));
- $reason = input('post.reason');
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('store_cancel', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('no_right'));
- }
- try {
- Db::startTrans();
- model('order', 'logic')->changeOrderStateCancel($order_info, 'seller', $this->seller_info['seller_name'], $reason);
- } catch (\Exception $e) {
- Db::rollback();
- ds_json_encode(10001, $e->getMessage());
- }
- Db::commit();
- ds_json_encode(10000, '', 1);
- }
-
- public function order_ship_price()
- {
- $order_id = intval(input('post.order_id'));
- $shipping_fee = ds_price_format(input('post.shipping_fee'));
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('modify_price', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('no_right'));
- }
- $result = model('order', 'logic')->changeOrderShipPrice($order_info, 'seller', $this->seller_info['seller_name'], $shipping_fee);
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- }
- ds_json_encode(10000, '', 1);
- }
-
- public function order_spay_price()
- {
- $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('store_id', '=', $this->store_info['store_id']);
- $goods_amount = input('post.order_fee');
- $order_info = $order_model->getOrderInfo($condition);
- $if_allow = $order_model->getOrderOperateState('spay_price', $order_info);
- if (!$if_allow) {
- ds_json_encode(10001, lang('no_right'));
- }
- $info = $logic_order->changeOrderSpayPrice($order_info, 'seller', $this->seller_info['seller_name'], $goods_amount);
- if ($info['code'] == TRUE) {
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
-
- public function order_deliver_send()
- {
- $order_id = intval(input('post.order_id'));
- if ($order_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $order_model = model('order');
- $condition = array();
- $condition[] = array('order_id', '=', $order_id);
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
- $if_allow_send = intval($order_info['lock_state']) || !in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND));
- if ($if_allow_send) {
- ds_json_encode(10001, lang('no_right'));
- }
-
- $extend = array(
- 'reciver_name' => $order_info['extend_order_common']['reciver_name'],
- 'reciver_info' => serialize($order_info['extend_order_common']['reciver_info']),
- 'deliver_explain' => $order_info['extend_order_common']['deliver_explain'],
- 'daddress_id' => !empty(input('post.daddress_id')) ? input('post.daddress_id') : $order_info['extend_order_common']['daddress_id'],
- 'shipping_express_id' => !empty(input('post.shipping_express_id')) ? input('post.shipping_express_id') : $order_info['extend_order_common']['shipping_express_id'],
- 'shipping_code' => !empty(input('post.shipping_code')) ? input('post.shipping_code') : $order_info['shipping_code'],
- );
- $result = model('order', 'logic')->changeOrderSend($order_info, 'seller', $this->seller_info['seller_name'], $extend);
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- }
- ds_json_encode(10000, lang('ds_common_op_succ'), 1);
- }
- }
|