You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.6 KiB
PHP
163 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace Admin\Controller;
|
|
|
|
use User\Api\UserApi as UserApi;
|
|
use Think\Controller;
|
|
|
|
/**
|
|
* 订单控制器
|
|
*
|
|
* @author 鹿文学
|
|
*/
|
|
class OrderController extends ThinkController
|
|
{
|
|
|
|
const model_name = 'Order';
|
|
|
|
/**
|
|
* 订单列表
|
|
*/
|
|
public function lists()
|
|
{
|
|
|
|
if (!empty($_REQUEST['order_number'])) {
|
|
$extend['order_number'] = array('like', '%' . $_REQUEST['order_number'] . '%');
|
|
}
|
|
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
|
|
$extend['order_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
|
|
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
|
|
$extend['order_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
|
|
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
|
|
$extend['order_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
|
|
}
|
|
if (is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id'] > 0) {
|
|
$extend['m.game_id'] = $_REQUEST['game_id'];
|
|
}
|
|
if (is_numeric($_REQUEST['pay_status'])) {
|
|
if (intval($_REQUEST['pay_status']) == 2) {
|
|
$extend['pay_status'] = 0;
|
|
$extend['order_time'] = array('lt', time() - 1800);
|
|
} elseif (intval($_REQUEST['pay_status']) == 0) {
|
|
$extend['pay_status'] = $_REQUEST['pay_status'];
|
|
$extend['order_time'] = array('egt', time() - 1800);
|
|
} else {
|
|
$extend['pay_status'] = $_REQUEST['pay_status'];
|
|
}
|
|
|
|
}
|
|
if (!empty($_REQUEST['keyword'])) {
|
|
$extend['game_name|title|server_name|small_account'] = array('like', '%' . $_REQUEST['keyword'] . '%');
|
|
}
|
|
$extend['admin_status'] = 0;
|
|
$this -> m_title = '订单列表';
|
|
$this -> meta_title = '订单列表';
|
|
$this -> assign('commonset', M('Kuaijieicon') -> where(['url' => 'Order/lists', 'status' => 1]) -> find());
|
|
$data = D(self::model_name) -> lists($_GET['p'], $extend);
|
|
$this -> assign('list_data', $data['data']);
|
|
$this -> assign('_page', $data['page']);
|
|
$this -> display();
|
|
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
|
|
$this -> update_status(I('request.ids'), - 2);
|
|
|
|
}
|
|
|
|
/**
|
|
* 订单状态
|
|
*/
|
|
public function update_status($ids = '', $status = 0)
|
|
{
|
|
$ids = $ids ? $ids : I('request.ids');
|
|
$field = 'pay_status';
|
|
if (empty($ids)) {
|
|
$this -> error('请选择要操作的数据');
|
|
}
|
|
$map['id'] = array('in', $ids);
|
|
switch ($status) {
|
|
case - 2 : /* 删除 */
|
|
$data = ['admin_status' => 1];
|
|
$msg = array('success' => '删除成功', 'error' => '删除失败');
|
|
break;
|
|
case 0 : /* 禁用 */
|
|
$data = [$field => 0];
|
|
$msg = array('success' => '禁用成功', 'error' => '禁用失败');
|
|
break;
|
|
case 1 : /* 成功 */
|
|
$data = [$field => 1];
|
|
$msg = array('success' => '交易成功', 'error' => '交易失败');
|
|
break;
|
|
case 2 : /* 驳回/拒绝 */
|
|
$data = [$field => 2];
|
|
$msg = array('success' => '取消成功', 'error' => '取消失败');
|
|
break;
|
|
case 3 :
|
|
$data = ['send_time' => time()];
|
|
$msg = array('success' => '发货成功', 'error' => '发货失败');
|
|
break;
|
|
case 4 :
|
|
$data = ['is_refund' => 1, 'pay_status' => 2];
|
|
$msg = array('success' => '退款成功', 'error' => '退款失败');
|
|
break;
|
|
case 5 :/* 补单 */
|
|
$orderModel = D(self::model_name);
|
|
$result = $orderModel->field('id, merchandise_id, seller_id')->where($map)->select();
|
|
$newIds = null;
|
|
$refundIds = null;
|
|
foreach ($result as $key => $value) {
|
|
$extend = array(
|
|
'pay_time'=>['gt', 0],
|
|
'seller_id'=>$value['seller_id'],
|
|
'merchandise_id'=>$value['merchandise_id'],
|
|
'id'=>['neq', $value['id']]
|
|
);
|
|
$orderData = $orderModel->field('id')->where($extend)->find();
|
|
if(empty($orderData)) {
|
|
$newIds[] = $value['id'];
|
|
} else {
|
|
$refundIds[] = $value['id'];
|
|
}
|
|
}
|
|
if(!empty($refundIds)) {
|
|
$orderModel->where(['id'=>['in',$refundIds]])->save(['is_refund'=>2]);
|
|
}
|
|
if(empty($newIds)) {
|
|
$this->error('补单失败,此商品已出售', U('lists'));
|
|
}
|
|
|
|
$map['id'] = ['in', $newIds];
|
|
$data = ['pay_time' => time(), 'pay_status' => 1];
|
|
$msg = array('success' => '补单成功', 'error' => '补单失败');
|
|
break;
|
|
default :
|
|
$this -> error('参数错误');
|
|
break;
|
|
}
|
|
$user = D('User');
|
|
if (D(self::model_name) -> where($map) -> save($data) !== false) {
|
|
switch ($status) {
|
|
case 3 :
|
|
{
|
|
$order = D(self::model_name) -> field('merchandise_id,real_money,seller_id,buyer_id,order_small_id') -> where(['id' => $ids]) -> find();
|
|
D('Merchandise') -> where(['id' => $order['merchandise_id']]) -> save(['over_time' => time(), 'status' => 1]);
|
|
$buyer = $user -> field('promote_id,promote_account,parent_id,parent_name') -> where(['id' => $order['buyer_id']]) -> find();
|
|
$user -> where(['id' => $order['order_small_id']]) -> save(['puid' => $order['buyer_id'], 'source_time' => time(), 'promote_id' => $buyer['promote_id'], 'promote_account' => $buyer['promote_account'], 'parent_id' => $buyer['parent_id'], 'parent_name' => $buyer['parent_name']]);
|
|
$gold_coin = $user -> field('gold_coin') -> where(['id' => $order['seller_id']]) -> find();
|
|
$user -> where(['id' => $order['seller_id']]) -> save(['gold_coin' => $gold_coin['gold_coin'] + $order['real_money']]);
|
|
};
|
|
break;
|
|
}
|
|
$this -> success($msg['success'], '', IS_AJAX);
|
|
} else {
|
|
$this -> error($msg['error'], '', IS_AJAX);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|