123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- class ChainOrder extends MobileChain {
- public function initialize() {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/chain.lang.php');
- }
-
- public function get_order_list() {
- $chain_order_model = model('chain_order');
- $condition = array();
- $condition[] = array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_NEW]);
- $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
- $search_name = input('get.search_name');
- if ($search_name != '') {
- $condition[] = array('order_sn|shipping_code', 'like', '%' . $search_name . '%');
- View::assign('search_name', $search_name);
- }
- $allow_state_array = array('state_default', 'state_arrive', 'state_pickup');
- $state_type = input('post.state_type');
- if (in_array($state_type, $allow_state_array)) {
- $condition[] = array('chain_order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_SEND, ORDER_STATE_PICKUP, ORDER_STATE_SUCCESS), $state_type));
- }
- $order_model = model('order');
- $chain_order_list = $chain_order_model->getChainOrderList($condition, '*', 10);
- foreach ($chain_order_list as $key => $val) {
- $chain_order_list[$key]['state_desc'] = get_order_state(array('order_state' => $val['chain_order_state']));
- $condition = array();
- $condition[] = array('order_id', '=', $val['order_id']);
- $extend_order_goods = $order_model->getOrdergoodsList($condition);
- foreach ($extend_order_goods as $k => $v) {
- $extend_order_goods[$k]['image_240_url'] = goods_cthumb($v['goods_image'], 240, $v['store_id']);
- }
- $chain_order_list[$key]['goods_list'] = $extend_order_goods;
- }
- $mobile_page = $chain_order_model->page_info;
- $chain_order_list = array_values($chain_order_list);
- $result = array_merge(array('chain_order_list' => $chain_order_list), mobile_page($mobile_page));
- ds_json_encode(10000, '', $result);
- }
-
- public function order_info() {
- $chain_order_id = intval(input('param.chain_order_id'));
- if (!$chain_order_id) {
- ds_json_encode(10001, lang('param_error'));
- }
- $chain_order_model = model('chain_order');
- $order_model = model('order');
- $condition = array();
- $condition[] = array('chain_order_id', '=', $chain_order_id);
- $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
- $order_info = $chain_order_model->getChainOrderInfo($condition);
- if (empty($order_info)) {
- ds_json_encode(10001, lang('store_order_none_existr'));
- }
- $order_info['state_desc'] = get_order_state(array('order_state' => $order_info['chain_order_state']));
- $condition = array();
- $condition[] = array('order_id', '=', $order_info['order_id']);
- $extend_order_goods = $order_model->getOrdergoodsList($condition);
- foreach ($extend_order_goods as $k => $v) {
- $extend_order_goods[$k]['image_240_url'] = goods_cthumb($v['goods_image'], 240, $v['store_id']);
- }
- $order_info['goods_list'] = $extend_order_goods;
- ds_json_encode(10000, '', array('chain_order_info' => $order_info));
- }
-
- public function search_deliver() {
- $chain_order_id = intval(input('post.chain_order_id'));
- if ($chain_order_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $chain_order_model = model('chain_order');
- $chain_order_info = $chain_order_model->getChainOrderInfo(array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id']));
- if (empty($chain_order_info)) {
- ds_json_encode(10001, lang('order_not_exist'));
- }
- $express = rkcache('express', true);
- $express_code = $chain_order_info['express_code'];
- $express_name = $chain_order_info['express_name'];
- $deliver_info = $this->_get_express($express_code, $chain_order_info['shipping_code'], $chain_order_info['reciver_mobphone']);
- ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $chain_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 arrive_point() {
- $chain_order_id = intval(input('param.chain_order_id'));
- if ($chain_order_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $chain_order_model = model('chain_order');
- $condition = array();
- $condition[] = array('chain_order_id', '=', $chain_order_id);
- $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
- $chain_order_info = $chain_order_model->getChainOrderInfo($condition);
- if (!$chain_order_info) {
- ds_json_encode(10001, lang('order_not_exist'));
- }
- $pickup_code = $this->createPickupCode();
-
- $update = array();
- $update['chain_order_pickup_code'] = $pickup_code;
- $chain_order_model->editChainOrderArrive($update, array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id']));
-
- $order_model = model('order');
- $order_model->editOrder(array('order_state' => ORDER_STATE_PICKUP), array(
- 'order_id' => $chain_order_info['order_id'],
- 'order_state' => ORDER_STATE_SEND
- ));
-
- model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendPickupcode','cron_value'=>serialize(array('pickup_code' => $pickup_code, 'order_id' => $chain_order_info['order_id']))));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- }
-
- public function pickup_parcel() {
- if (!request()->isPost()) {
-
- } else {
- $chain_order_id = intval(input('post.chain_order_id'));
- $pickup_code = intval(input('post.pickup_code'));
- if ($chain_order_id <= 0 || $pickup_code <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $chain_order_model = model('chain_order');
- $chain_order_info = $chain_order_model->getChainOrderInfo(array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id'], 'chain_order_lock_state' => 0, 'chain_order_pickup_code' => $pickup_code));
- if (empty($chain_order_info)) {
- ds_json_encode(10001, lang('pickup_code_error'));
- }
- $result = $chain_order_model->editChainOrderPickup(array(), array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id'], 'chain_order_lock_state' => 0, 'chain_order_pickup_code' => $pickup_code));
- if ($result) {
-
- $order_info = model('order')->getOrderInfo(array('order_id' => $chain_order_info['order_id']));
- model('order', 'logic')->changeOrderStateReceive($order_info, 'buyer', lang('chain'), lang('chain_receive_goods'));
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- }
-
- private function createPickupCode() {
- return rand(1, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9);
- }
- }
|