function __construct()
 {
     parent::__construct();
     parent::_checkLogin();
     $this->adminConfig = C('steward/admin');
     $this->steSetting = C('steward/setting');
     parent::_authUser(array(1, 7, 9));
 }
 public function edit_worker_save()
 {
     parent::_authUser(array(1, 2, 9));
     $id = $this->_postid('order_id', 0);
     $type = $this->_postid('type', 1);
     $workerUid = $this->_postid('worker_uid', 0);
     if (!$id) {
         $this->JsonReturn('参数丢失');
     }
     $rs = M('ste_order')->where(array('order_id' => $id))->find();
     if (!$rs) {
         $this->JsonReturn('订单不存在');
     }
     if (parent::_checkIsPresident()) {
         //社长
         if ($rs['service_id'] != steadmin::$adminInfo['service_id']) {
             $this->JsonReturn('没有操作权限!');
         }
     } elseif (!parent::_checkIsAdmin()) {
         $this->JsonReturn('没有操作权限');
     }
     //判断当前订单是否可以修改
     if (!in_array($rs['status'], array(3, 4, 5, 6))) {
         $this->JsonReturn('该订单当前状态不可编辑');
     }
     $field = '';
     switch ($type) {
         case 1:
             if ($workerUid == $rs['deployment_uid']) {
                 $this->JsonReturn('配货员未变更');
             }
             $field = 'deployment_uid';
             $msgId = 1;
             $oldUid = $rs['deployment_uid'];
             break;
         case 2:
             if ($workerUid == $rs['worker_uid']) {
                 $this->JsonReturn('小管家未变更');
             }
             $field = 'worker_uid';
             $msgId = 2;
             $oldUid = $rs['worker_uid'];
             break;
     }
     if (!$field) {
         $this->JsonReturn('参数有误');
     }
     //更新数据
     $info = M('ste_order')->update(array($field => $workerUid), array('order_id' => $id));
     if (!$info) {
         $this->JsonReturn('编辑失败');
     }
     $res = array();
     //通知小管家
     $res['deployment'] = $this->_sendQIYENotice($rs, $msgId, $workerUid);
     $res['deployment_old'] = $this->_sendQIYENotice($rs, 4, $oldUid);
     //===记录操作日志====
     parent::saveSySLog(2, array('field' => $field, 'user_id' => $workerUid, 'old_user_id' => $oldUid), $id, array(), '订单管理-更换小管家');
     //===记录操作日志====
     //返回结果
     $this->JsonReturn('ok', $res, 1);
 }
 public function deal()
 {
     parent::_authUser(array(1, 5, 7, 9));
     $id = $this->_postid('id', 0);
     $act = $this->_postid('act', 0);
     $action = $this->_post('action', '');
     if (!$id) {
         showError('参数丢失');
     }
     $rs = M('ste_shop')->where(array('shop_id' => $id, 'city_id' => steadmin::$adminInfo['city_id']))->find();
     if (!$rs) {
         showError('店铺不存在');
     }
     if (!parent::_checkUser($rs['user_id'], $id) && (parent::_checkIsPresident() && $rs['service_id'] != steadmin::$adminInfo['service_id'])) {
         showError('编辑权限不足');
     }
     if ($action) {
         if (in_array($action, array('up', 'down'))) {
             if ($action == 'up') {
                 $count = M('ste_goods')->update(array('status' => 1), array('status' => 0, 'shop_id' => $id));
             } else {
                 $count = M('ste_goods')->update(array('status' => 0), array('status' => 1, 'shop_id' => $id));
             }
             //===记录操作日志====
             parent::saveSySLog(4, array('status' => $action, 'table' => 'goods'), $id, array('shop_id' => $id), '店铺管理-更新店铺商品状态');
             //===记录操作日志====
             $this->JsonReturn('ok', $count, 1);
         } else {
             $this->JsonReturn('参数错误');
         }
     } else {
         if (!isset($this->steSetting['shop_status'][$act])) {
             showError('参数错误');
         }
         M('ste_shop')->update(array('status' => $act), array('shop_id' => $id));
         //===记录操作日志====
         parent::saveSySLog(4, array('status' => $act), $id, array('shop_id' => $id), '店铺管理-处理状态');
         //===记录操作日志====
         $this->JsonReturn('ok', $this->steSetting['shop_status'][$act], 1);
     }
 }
 function __construct()
 {
     parent::__construct();
     parent::_checkLogin();
     parent::_authUser(array(1));
 }
 /**
  * 列表
  */
 public function index()
 {
     parent::_authUser(array(1, 2, 5, 6, 7, 8, 9));
     $title = $this->_get('q');
     //关键字搜索
     $st = $this->_get('st', 'order_sn');
     //关键字搜索
     $deal = $this->_get('deal', '');
     //分组查看
     $orderType = $this->_getid('order_type', 0);
     //类别
     $serviceId = $this->_getid('service_id', 0);
     //服务社
     $villageId = $this->_getid('village_id', 0);
     //小区
     $orderSource = $this->_getid('order_source', 0);
     //客户端
     $uid = $this->_getid('uid', 0);
     //商圈
     $startTime = $this->_get('stime', '');
     //开始时间
     $endTime = $this->_get('etime', '');
     //结束时间
     $status = $this->_getid('status', 0);
     //状态
     $p = $this->_getid('p', 1);
     $searchType = array('order_sn' => 'order_sn', 'phone' => 'phone', 'username' => 'username');
     $dealAction = array('service' => array('status' => array(1, 3, 4, 5, 13), 'arrive_date[<=]' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))), 'finance' => array('status' => array(9, 10)));
     //报表页面每页显示数量为100
     if ($deal == 'report') {
         jumpTo(U('report/today'));
     }
     $where = array();
     if ($deal && isset($dealAction[$deal])) {
         $where = $dealAction[$deal];
     }
     if (isset($_GET['q']) && !$_GET['q']) {
         unset($_GET['q']);
     }
     if ($deal == 'service') {
         $pageShow = 80;
     } else {
         $pageShow = 20;
     }
     if ($title && $st == 'user') {
         $user = D('member')->field('uid')->where(array('nickname' => $title))->findAll(false);
         if ($user) {
             $uid = array();
             foreach ($user as $v) {
                 $uid[] = $v['uid'];
             }
             $title = '';
         }
     } elseif ($title && $st == 'uid') {
         $uid = $title;
         $title = '';
     }
     if ($title && isset($searchType[$st])) {
         $where['LIKE'] = array($searchType[$st] => parent::safeSearch($title));
     }
     if ($orderType) {
         $where['order_type'] = $orderType - 1;
     }
     if ($serviceId) {
         $where['service_id'] = $serviceId;
     }
     if ($villageId) {
         $where['village_id'] = $villageId;
     }
     if ($orderSource) {
         $where['order_source'] = $orderSource - 1;
     }
     if ($uid) {
         $where['uid'] = $uid;
     }
     if ($startTime && $endTime) {
         $where['arrive_date[>=]'] = inTime($startTime);
         $where['arrive_date[<=]'] = inTime($endTime) + 60 * 60 * 24 - 1;
     }
     if ($status) {
         $where['status'] = $status - 1;
     }
     if (parent::_checkIsPresident()) {
         //社长
         $where['service_id'] = steadmin::$adminInfo['service_id'];
     } elseif (!parent::_checkIsAdmin()) {
         showError('抱歉,暂时无法查看所属订单');
     }
     $rs = M('ste_order')->where($where)->page($p, $pageShow)->order('order_id DESC')->findAll();
     $total = M('ste_order')->getTotal();
     //        z(M('ste_shop')->getAllSql());
     //        z($rs);
     if ($rs) {
         foreach ($rs as $k => $v) {
             $userName = getUser($v['uid']);
             $rs[$k]['userName'] = $userName ? $userName : $v['username'];
             $rs[$k]['villageName'] = parent::getVillageName($v['village_id']);
             $rs[$k]['serviceName'] = isset($this->serviceData[$v['service_id']]) ? $this->serviceData[$v['service_id']]['stitle'] : '';
         }
     }
     $lastOrderId = M('ste_order')->order('order_id DESC')->getField('order_id');
     //
     $this->steSetting['order_status'][1] = '<span class="red">已支付</span>';
     $this->assign(array('pageShow' => $pageShow, 'rs' => $rs, 'total' => $total, 'p' => $p, 'lastOrderId' => $lastOrderId, 'service_id' => $serviceId, 'order_type' => $orderType, 'startTime' => $startTime, 'endTime' => $endTime, 'title' => $title, 'status' => $status, 'orderSource' => $orderSource, 'service' => $this->serviceData, 'setting' => $this->steSetting, 'setOrderStaus' => $this->setOrderStatus));
     $this->display();
 }
 public function batch()
 {
     parent::_checkLogin();
     parent::_authUser(array(1, 2, 5, 7, 8));
     $gids = $this->_post('gid');
     if (!$gids || !is_array($gids)) {
         $this->JsonReturn('请先选择需要操作的商品');
     }
     $objData = array();
     $list = array('original_price', 'price_pre', 'price', 'storage_counts', 'start_times', 'end_times', 'px', 'cate_id', 'order_counts');
     foreach ($list as $val) {
         $objData[$val] = $this->_post($val, '');
     }
     //内容规则检查
     T('content/validate');
     $validate = array();
     if ($objData['price']) {
         $validate[] = array('price', 'currency', '商品价格不正确');
     } else {
         unset($objData['price']);
     }
     if ($objData['storage_counts']) {
         $validate[] = array('storage_counts', 'int', '库存不正确');
     } else {
         unset($objData['storage_counts']);
     }
     if ($objData['original_price']) {
         $validate[] = array('original_price', 'currency', '商品原始价格不正确');
     } else {
         unset($objData['original_price']);
     }
     if ($objData['start_times']) {
         $objData['start_times'] = inTime($objData['start_times']);
     } else {
         unset($objData['start_times']);
     }
     if ($objData['end_times']) {
         $objData['end_times'] = inTime($objData['end_times']);
     } else {
         unset($objData['end_times']);
     }
     if (!$objData['cate_id']) {
         unset($objData['cate_id']);
     }
     if (!$objData['price_pre']) {
         unset($objData['price_pre']);
     }
     if ($objData['px'] !== '') {
         $objData['px'] = intval($objData['px']);
     } else {
         unset($objData['px']);
     }
     if ($objData['order_counts'] !== '') {
         $objData['order_counts'] = intval($objData['order_counts']);
     } else {
         unset($objData['order_counts']);
     }
     if (!$objData) {
         $this->JsonReturn('必须有修改项!');
     }
     if ($validate && !validate::check($validate, $objData)) {
         $this->JsonReturn(validate::getError());
     }
     //补充数据
     $objData['refresh_time'] = TIME;
     //        z($objData);
     //取出所以商品,并对商品做权限判断
     $rs = M('ste_goods')->field('user_id,gid,shop_id')->where(array('gid' => $gids))->findAll(false);
     if (!$rs) {
         $this->JsonReturn('没有找到符合条件的商品');
     }
     $ids = array();
     foreach ($rs as $val) {
         if (!parent::_checkUser($val['user_id'], $val['shop_id'])) {
             $this->JsonReturn('操作错误,没有编辑权限');
         } else {
             $ids[] = $val['gid'];
         }
     }
     if ($ids) {
         $total = M('ste_goods')->update($objData, array('gid' => $ids));
         //===记录操作日志====
         parent::saveSySLog(4, $objData, $ids, array('gid' => $ids), '商品管理-批量设置');
         //===记录操作日志====
         $this->JsonReturn('ok', $total, 1);
     } else {
         $this->JsonReturn('没有找到符合条件的商品');
     }
 }