public function editOrder() { if (IS_POST) { $order_id = intval($_POST['order_id']); $issuper = M('Admin')->where(array('admin_id' => AID))->getField('admin_issuper'); if (!$issuper) { $order_where['creat_admin_id'] = array('in', '0,' . AID); } $order_where['order_id'] = $order_id; $order = $this->model->where($order_where)->find(); if (empty($order)) { $this->error('非法操作'); } $data['order_sn'] = order_sn(); $data['out_sn'] = str_rp($_POST['out_sn'], 1); $data['buyer_name'] = str_rp($_POST['true_name'], 1); $data['payment_time'] = strtotime($_POST['payment_time']); $data['add_time'] = strtotime($_POST['add_time']); $data['discount'] = floatval($_POST['discount']); $data['order_amount'] = floatval($_POST['order_amount']); $data['email'] = str_rp($_POST['email'], 1); if ($data['email']) { saveContact($data['email'], 'email', '订单'); $member_id = M('Member')->where(array('email' => $data['email']))->getField('member_id'); } $data['mobile'] = str_rp($_POST['mob_phone'], 1); if ($data['mobile']) { saveContact($data['mobile'], 'mobile', '订单'); $member_id = M('Member')->where(array('mobile' => $data['mobile']))->getField('member_id'); } if ($member_id) { $data['member_id'] = $member_id; } else { $data['member_id'] = 0; } $data['source'] = str_rp($_POST['source'], 1); $data['creat_admin_id'] = AID; $data['customer_id'] = intval($_POST['customer_id']); $res = $this->model->where($order_where)->save($data); $data['OrderAddress']['company_name'] = str_rp($_POST['company_name'], 1); $data['OrderAddress']['true_name'] = $data['buyer_name']; $data['OrderAddress']['buyer_id'] = $data['member_id']; $data['OrderAddress']['prov_id'] = intval($_POST['province_id']); $data['OrderAddress']['city_id'] = intval($_POST['city_id']); $data['OrderAddress']['area_id'] = intval($_POST['area_id']); $data['OrderAddress']['address'] = str_rp($_POST['address'], 1); $data['OrderAddress']['zip_code'] = intval($_POST['zip_code']); $data['OrderAddress']['mob_phone'] = $data['mobile']; $data['OrderAddress']['email'] = $data['email']; $data['OrderAddress']['add_time'] = $data['add_time']; M('OrderAddress')->where(array('order_id' => $order_id))->save($data['OrderAddress']); $data['OrderLog'][0]['order_state'] = '订单完成'; $data['OrderLog'][0]['log_time'] = $data['add_time']; $data['OrderLog'][0]['state_info'] = '管理员录入订单'; $data['OrderLog'][0]['operator'] = '管理员-' . get_admin_nickname(AID); M('OrderLog')->where(array('order_id' => $order_id))->add($data['OrderLog'][0]); foreach ($_POST['goods'] as $key => $val) { $goods = M('Goods')->where(array('goods_id' => $val['goods_id']))->find(); if (!empty($goods)) { $data['OrderGoods'][$key]['order_id'] = $order_id; $data['OrderGoods'][$key]['goods_id'] = $goods['goods_id']; $data['OrderGoods'][$key]['goods_price'] = $val['goods_price']; $data['OrderGoods'][$key]['goods_mkprice'] = $val['goods_mktprice']; $data['OrderGoods'][$key]['goods_num'] = $val['goods_num']; $data['OrderGoods'][$key]['goods_name'] = $goods['goods_name']; $data['OrderGoods'][$key]['goods_image'] = $goods['goods_pic']; } } M('OrderGoods')->where(array('order_id' => $order_id))->delete(); M('OrderGoods')->addAll($data['OrderGoods']); if (empty(intval($_POST['customer_id']))) { $customer['company_name'] = str_rp($_POST['company_name'], 1); $customer['customer_name'] = $data['buyer_name']; $customer['province_id'] = intval($_POST['province_id']); $customer['city_id'] = intval($_POST['city_id']); $customer['district_id'] = intval($_POST['area_id']); $customer['address'] = str_rp($_POST['address'], 1); $customer['zip_code'] = intval($_POST['zip_code']); $customer['mobile'] = $data['mobile']; $customer['email'] = $data['email']; $customer['creat_admin_id'] = AID; $customer['create_time'] = NOW_TIME; $customer['status'] = 1; $customer['remark'] = '来自订单录入'; $customer['sort'] = 0; if (!empty($customer['company_name']) || !empty($customer['customer_name'])) { M('Customer')->add($customer); } } if ($res) { $this->success('录入订单成功', U('order')); } else { $this->error('录入订单失败'); } } elseif (IS_GET) { $order_id = intval($_GET['order_id']); $order_where['order_id'] = $order_id; $issuper = M('Admin')->where(array('admin_id' => AID))->getField('admin_issuper'); if (!$issuper) { $order_where['creat_admin_id'] = array('in', '0,' . AID); } $order = $this->model->relation(true)->where($order_where)->find(); if (empty($order)) { $this->error('非法操作'); } else { $this->order = $order; } $province = M('District')->where(array('level' => 1, 'status' => 1))->order('d_sort')->select(); $city = M('District')->where(array('level' => 2, 'status' => 1, 'upid' => $order['prov_id']))->order('d_sort')->select(); $area = M('District')->where(array('level' => 3, 'status' => 1, 'upid' => $order['city_id']))->order('d_sort')->select(); $this->assign('province', $province); $this->assign('city', $city); $this->assign('area', $area); $this->display('addOrder'); } }
public function allot() { if (IS_AJAX) { $rp_sn = trimall($_POST['rp_sn']); $admin_id = intval($_POST['admin_id']); $admin_id = M('Member')->where(array('member_id' => $admin_id, 'admin_type' => 1))->getField('member_id'); $data['admin_id'] = $admin_id; $data['rp_status'] = 1; //-1取消维修,0会员提交订单,1管理员分配订单,2维修工程师提交报价单,3管理员确认报价单,4会员支付维修报价,5维修工程师维修设备,6维修工程师发货确认,7会员收货确认 $res = $this->model->where(array('rp_sn' => $rp_sn))->save($data); if ($res) { //写入维修日志 $log['rp_id'] = $this->model->where(array('rp_sn' => $rp_sn))->getField('rp_id'); $log['log_content'] = '平台将维修订单分配给维修工程师' . get_admin_nickname($admin_id); $log['is_view'] = 1; $log['log_time'] = NOW_TIME; M('RepairLog')->add($log); $result['code'] = 200; $result['msg'] = '平台将维修订单分配给维修工程师.'; $result['data'] = get_member_nickname($admin_id); } else { $result['code'] = 300; $result['msg'] = '分配维修工程师失败.'; $result['data'] = array(); } echo json_encode($result); } else { echo '非法操作'; } }