Commit f13850ed by 朱继来

Merge branch 'zjl_export_20191106'

parents 0b4be6e3 f11d6917
...@@ -12,6 +12,8 @@ use App\Http\Controllers\PermController; ...@@ -12,6 +12,8 @@ use App\Http\Controllers\PermController;
use App\Http\Error; use App\Http\Error;
use App\Model\UserMainModel; use App\Model\UserMainModel;
use App\Model\OrderModel; use App\Model\OrderModel;
use App\Model\CrmModel;
use App\Model\CmsModel;
use Excel; use Excel;
Class AddOrderController extends Controller Class AddOrderController extends Controller
...@@ -96,11 +98,9 @@ Class AddOrderController extends Controller ...@@ -96,11 +98,9 @@ Class AddOrderController extends Controller
$UserMainModel = new UserMainModel; $UserMainModel = new UserMainModel;
if(!empty($user_id) && strlen($request->input('user_id'))<11 ){ if(!empty($user_id) && strlen($request->input('user_id'))<11 ){
$user = $UserMainModel->where('user_id', $user_id)->select('user_id', 'email','mobile', 'is_test')->orderBy('create_time', 'desc')->first(); $user = $UserMainModel->where('user_id', $user_id)->select('user_id', 'email','mobile', 'is_test')->orderBy('create_time', 'desc')->first();
}else{ }else{
if (preg_match('/@/', $mobile)) { if (preg_match('/@/', $mobile)) {
$user = $UserMainModel->where('email', $mobile)->select('user_id', 'email', 'is_test')->orderBy('create_time', 'desc')->first(); $user = $UserMainModel->where('email', $mobile)->select('user_id', 'email', 'is_test')->orderBy('create_time', 'desc')->first();
} else { } else {
...@@ -108,47 +108,53 @@ Class AddOrderController extends Controller ...@@ -108,47 +108,53 @@ Class AddOrderController extends Controller
} }
} }
if (empty($user)) return ['errcode' => -1, 'errmsg' => '未找用户信息'];
// $perm = new PermController;
// $role = $perm->getUserRole($request); // 用户角色
// if ($goods_type == 1 || ($goods_type == 2 && !in_array($role, [1, 10, 11]))) { // 自营管理员、主管、主管助理可以帮客服下单
// $last_sale_id = $this->findLastSaleId($user->user_id);
if (!empty($user)) { // if ($last_sale_id && $operator_id != $last_sale_id) return ['errcode' => -1, 'errmsg' => '暂不能跟进该客户,请联系主管重新指派'];
$perm = new PermController; // }
$role = $perm->getUserRole($request); // 用户角色
if ($goods_type == 1 || ($goods_type == 2 && !in_array($role, [1, 10, 11]))) { // 自营管理员、主管、主管助理可以帮客服下单 if (strpos($_SERVER['HTTP_HOST'], 'sz') === false) { // 非测试环境下执行
$last_sale_id = $this->findLastSaleId($user->user_id); // 若用户已分配,则判断当前登录客服是否能给用户下单,若没分配,按之前流程,订单生成时分配给当前登录客服
$CrmModel = new CrmModel();
$sale_id = $CrmModel->getSaleId($user->user_id);
if ($last_sale_id && $operator_id != $last_sale_id) return ['errcode' => -1, 'errmsg' => '暂不能跟进该客户,请联系主管重新指派']; if ($sale_id && $sale_id != $operator_id) {
$CmsModel = new CmsModel();
$sale_name = $CmsModel->getUserName($sale_id);
return ['errcode' => -1, 'errmsg' => '该客户由 '.$sale_name.' 跟进,请联系主管重新指派'];
} }
}
$address = DB::connection('order')->table('lie_user_address')->where('user_id', $user->user_id)->get(); // 收货地址
$invoice = DB::connection('order')->table('lie_taxinfo')->where('user_id', $user->user_id)->get(); // 发票信息
$info['user'] = $user;
$info['address'] = $address;
$info['invoice'] = $invoice;
$address = DB::connection('order')->table('lie_user_address')->where('user_id', $user->user_id)->get(); // 收货地址 return ['errcode' => 0, 'errmsg' => '', 'data' => $info];
$invoice = DB::connection('order')->table('lie_taxinfo')->where('user_id', $user->user_id)->get(); // 发票信息
$info['user'] = $user;
$info['address'] = $address;
$info['invoice'] = $invoice;
}
if (isset($info)) {
return ['errcode' => 0, 'errmsg' => '', 'data' => $info];
} else {
return ['errcode' => -1, 'errmsg' => '未找用户信息'];
}
} }
} }
// 获取用户最近的订单跟进业务员 // 获取用户最近的订单跟进业务员
public function findLastSaleId($user_id) // public function findLastSaleId($user_id)
{ // {
$OrderModel = new OrderModel; // $OrderModel = new OrderModel;
$map['user_id'] = $user_id; // $map['user_id'] = $user_id;
$map['is_type'] = 0; // 过滤尽调数据 // $map['is_type'] = 0; // 过滤尽调数据
$map[] = ['sale_id', '>', 0]; // $map[] = ['sale_id', '>', 0];
$order = $OrderModel->where($map)->select('sale_id')->orderBy('order_id', 'desc')->first(); // $order = $OrderModel->where($map)->select('sale_id')->orderBy('order_id', 'desc')->first();
return $order ? $order['sale_id'] : 0; // return $order ? $order['sale_id'] : 0;
} // }
// 选择收货地址 // 选择收货地址
public function selectAddr(Request $request) public function selectAddr(Request $request)
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class CrmModel extends Model
{
protected $connection = 'crm';
protected $table = 'user';
protected $primaryKey = 'user_id';
public $timestamps = false;
// 获取用户绑定的业务员ID
public function getSaleId($user_id)
{
$user = $this->where('outter_uid', $user_id)->select('user_id')->first();
if (!$user) return false;
$sales = $this->from('salesman')->where('user_id', $user->user_id)->select('sale_id')->first();
return $sales ? $sales->sale_id : 0;
}
}
\ No newline at end of file
...@@ -83,6 +83,20 @@ return [ ...@@ -83,6 +83,20 @@ return [
'prefix' => '', 'prefix' => '',
'strict' => false, 'strict' => false,
], ],
'crm' => [
'driver' => 'mysql',
'host' => env('DB_HOST_CRM', ''),
'database' => env('DB_DATABASE_CRM', ''),
'username' => env('DB_USERNAME_CRM', ''),
'password' => env('DB_PASSWORD_CRM', ''),
'port' => env('DB_PORT', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => env('DB_PREFIX_CRM', ''),
'strict' => false,
],
'pcb' => [ 'pcb' => [
'driver' => 'mysql', 'driver' => 'mysql',
'host' => env('DB_HOST_PCB', ''), 'host' => env('DB_HOST_PCB', ''),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment