Commit a322fafb by 朱继来

调整DB

parent 8834f8e9
......@@ -8,6 +8,10 @@ use Illuminate\Foundation\Inspiring;
use DB;
use Log;
use Illuminate\Support\Facades\Redis;
use App\Model\RegionModel;
use App\Model\OrderModel;
use App\Model\OrderAddressModel;
class JingDiaoOrderAddress extends Command
{
/**
......@@ -38,7 +42,7 @@ class JingDiaoOrderAddress extends Command
protected function getregion($parent_id = 0){
$str = "";
if($parent_id != 1){
$region = DB::Connection("order")->table("lie_region")->where(["region_id"=>$parent_id])->first();
$region = RegionModel::where(["region_id"=>$parent_id])->first();
$str = $region->region_name." ".$str;
if($region && $region->parent_id != 1){
$str = $this->getregion($region->parent_id)." ".$str;
......@@ -80,7 +84,7 @@ class JingDiaoOrderAddress extends Command
// }
//return;
DB::Connection("order")->table("lie_order")->where(["is_type"=>1])->orderBy("order_id","desc")->chunk(100,function($orders){
OrderModel::where(["is_type"=>1])->orderBy("order_id","desc")->chunk(100,function($orders){
foreach($orders as $order){
try{
......@@ -103,7 +107,7 @@ class JingDiaoOrderAddress extends Command
$str = mb_substr($orderRemark,0,2);
$region = DB::Connection("order")->table("lie_region")->whereRaw("region_name like '{$str}%'")->first();
$region = RegionModel::whereRaw("region_name like '{$str}%'")->first();
if(!$region){
......@@ -140,7 +144,7 @@ class JingDiaoOrderAddress extends Command
//生成随机地址
protected function getRandomAddress(){
$random = rand(1,367456);
$address = DB::Connection("order")->table("lie_order_address")->where(["order_address_id"=>$random])->first();
$address = OrderAddressModel::where(["order_address_id"=>$random])->first();
if($address){
return $address;
}else{
......
......@@ -124,27 +124,27 @@ class JingDiaoUser extends Command
*/
public function handle(){
$userids = $this->userids();
$users = DB::Connection("order")->table("lie_user_main")->whereIn("user_id",$userids)->where("is_type","=",1)->pluck("user_id");
$users = DB::Connection("web")->table("lie_user_main")->whereIn("user_id",$userids)->where("is_type","=",1)->pluck("user_id");
try{
DB::Connection("order")->beginTransaction();
DB::Connection("web")->beginTransaction();
foreach($users as $user_id){
DB::Connection("order")->table("lie_user_main")->where(["user_id"=>$user_id])->update([
DB::Connection("web")->table("lie_user_main")->where(["user_id"=>$user_id])->update([
"is_type"=>0,
]);
continue;
$zjf_z = DB::Connection("order")->table("lie_point_log")->where("user_id",$user_id)->where("flow_type",1)->sum("flow_point");
$zjf_f = DB::Connection("order")->table("lie_point_log")->where("user_id",$user_id)->where("flow_type",2)->sum("flow_point");
$zjf_z = DB::Connection("web")->table("lie_point_log")->where("user_id",$user_id)->where("flow_type",1)->sum("flow_point");
$zjf_f = DB::Connection("web")->table("lie_point_log")->where("user_id",$user_id)->where("flow_type",2)->sum("flow_point");
$jifen = intval($zjf_z - $zjf_f);
dump(sprintf("userid:%s 的积分为:%s",$user_id,$jifen));
$userInfo = DB::Connection("order")->table("lie_user_info")->where(["user_id"=>$user_id])->select("cur_user_point","cur_total_point")->first();
$userInfo = DB::Connection("web")->table("lie_user_info")->where(["user_id"=>$user_id])->select("cur_user_point","cur_total_point")->first();
$bk = DB::Connection("order")->table("lie_user_info")->where(["user_id"=>$user_id])->update([
$bk = DB::Connection("web")->table("lie_user_info")->where(["user_id"=>$user_id])->update([
"cur_user_point"=>$jifen,
"cur_total_point"=>$jifen,
]);
......@@ -153,10 +153,10 @@ class JingDiaoUser extends Command
}
DB::Connection("order")->commit();
DB::Connection("web")->commit();
}catch(\Exception $e){
dump($e->getMessage());
DB::Connection("order")->rollBack();
DB::Connection("web")->rollBack();
}
}
......@@ -169,11 +169,11 @@ class JingDiaoUser extends Command
{
$userids = $this->userids();
$users = DB::Connection("order")->table("lie_user_main")->whereIn("user_id",$userids)->where("is_type","=",1)->pluck("user_id");
$users = DB::Connection("web")->table("lie_user_main")->whereIn("user_id",$userids)->where("is_type","=",1)->pluck("user_id");
try{
DB::Connection("order")->beginTransaction();
DB::Connection("web")->beginTransaction();
......@@ -187,7 +187,7 @@ class JingDiaoUser extends Command
->select("order_amount","order_goods_type","is_type","order_pay_type","integral","status","order_id","create_time")->get();
// dump($orders);
$zong_jifen = 0;
$userMobile = DB::Connection("order")->table("lie_user_main")->where("user_id",$user_id)->select("mobile")->first();
$userMobile = DB::Connection("web")->table("lie_user_main")->where("user_id",$user_id)->select("mobile")->first();
foreach($orders as $k=>$order){
$jifen = 0;
if($order->order_pay_type == 3){
......@@ -220,7 +220,7 @@ class JingDiaoUser extends Command
];
// dump($jifenData);
$bk = DB::Connection("order")->table("lie_point_log")->insert($jifenData);
$bk = DB::Connection("web")->table("lie_point_log")->insert($jifenData);
if(!$bk){
throw new \Exception("添加数据失败");
}
......@@ -228,16 +228,16 @@ class JingDiaoUser extends Command
$zong_jifen += $jifen;
}
$zong_jifen = intval($zong_jifen);
$userInfo = DB::Connection("order")->table("lie_user_info")->where(["user_id"=>$user_id])->select("cur_user_point","cur_total_point")->first();
$userInfo = DB::Connection("web")->table("lie_user_info")->where(["user_id"=>$user_id])->select("cur_user_point","cur_total_point")->first();
if(!$userInfo){
$userInfo = DB::Connection("order")->table("lie_user_info")->insert([
$userInfo = DB::Connection("web")->table("lie_user_info")->insert([
"user_id"=>$user_id,
"cur_user_point"=>$zong_jifen,
"cur_total_point"=>$zong_jifen,
]);
}
DB::Connection("order")->table("lie_user_info")->where(["user_id"=>$user_id])->update([
DB::Connection("web")->table("lie_user_info")->where(["user_id"=>$user_id])->update([
"cur_user_point"=>$userInfo->cur_user_point,
"cur_total_point"=>$userInfo->cur_total_point,
]);
......@@ -249,11 +249,11 @@ class JingDiaoUser extends Command
}
DB::Connection("order")->commit();
DB::Connection("web")->commit();
}catch(\Exception $e){
dump($e->getMessage());
DB::Connection("order")->rollBack();
DB::Connection("web")->rollBack();
}
......@@ -360,7 +360,7 @@ class JingDiaoUser extends Command
}
$count = DB::connection('order')
$count = DB::connection('web')
->table('lie_user_main')
......@@ -384,13 +384,13 @@ class JingDiaoUser extends Command
$countN=0;
$userJD = [];
DB::Connection("order")->table("lie_user_main")->select("user_id","mobile","is_type")->OrderBy("user_id","desc")->whereRaw(" is_type = 1 and mobile != '' ")
DB::Connection("web")->table("lie_user_main")->select("user_id","mobile","is_type")->OrderBy("user_id","desc")->whereRaw(" is_type = 1 and mobile != '' ")
->chunk(100, function($users) use(&$countN,&$userJD) {
foreach ($users as $user) {
$user_id = $user->user_id;
$logs = null;
$orders = null;
$logs = DB::Connection("order")->table("lie_user_login")->where(["user_id"=>$user_id])->count("id");
$logs = DB::Connection("web")->table("lie_user_login")->where(["user_id"=>$user_id])->count("id");
$orders = DB::Connection("order")->table("lie_order")->where(["user_id"=>$user_id,"is_type"=>0])->count("order_id");
if(!$logs && !$orders){
dump($user->user_id);
......@@ -417,7 +417,7 @@ class JingDiaoUser extends Command
$redis->hset("api_email",$email,$user->user_id);
DB::Connection("order")->table("lie_user_main")->where(["user_id"=>$user->user_id])->update([
DB::Connection("web")->table("lie_user_main")->where(["user_id"=>$user->user_id])->update([
"mobile"=>"",
"email"=>$email
]);
......
......@@ -11,7 +11,17 @@ use App\Http\Page;
use App\Http\Controllers\PermController;
use App\Http\Error;
use App\Model\UserMainModel;
use App\Model\UserAddressModel;
use App\Model\TaxInfoModel;
use App\Model\InvoiceCompanyModel;
use App\Model\RegionModel;
use App\Model\ShoppingCartModel;
use App\Model\OrderModel;
use App\Model\OrderExtendModel;
use App\Model\OrderPriceModel;
use App\Model\ShoppingCartModel;
use App\Model\PayLogModel;
use App\Model\OrderActionLogModel;
use App\Model\CrmModel;
use App\Model\CmsModel;
use Excel;
......@@ -206,7 +216,7 @@ Class AddOrderController extends Controller
}
}
$address = DB::connection('order')->table('lie_user_address')->where('user_id', $user->user_id)->select('address_id', 'consignee')->get(); // 收货地址
$address = UserAddressModel::where('user_id', $user->user_id)->select('address_id', 'consignee')->get(); // 收货地址
// $invoice = DB::connection('order')->table('lie_taxinfo')->where('user_id', $user->user_id)->select('tax_id', 'tax_title')->get(); // 发票信息
$info['user'] = $user;
......@@ -237,7 +247,7 @@ Class AddOrderController extends Controller
if ($request->isMethod('post')) {
$address_id = $request->input('address_id');
$address = DB::connection('order')->table('lie_user_address')->where('address_id', $address_id)->first();
$address = UserAddressModel::where('address_id', $address_id)->first();
$address->province_val = $this->getAddress($address->province);
$address->city_val = $this->getAddress($address->city);
......@@ -253,7 +263,7 @@ Class AddOrderController extends Controller
if ($request->isMethod('post')) {
$tax_id = $request->input('tax_id');
$invoice = DB::connection('order')->table('lie_taxinfo')->where('tax_id', $tax_id)->first();
$invoice = TaxInfoModel::where('tax_id', $tax_id)->first();
$invoice->province_val = $invoice->consignee_province ? $this->getAddress($invoice->consignee_province) : '';
$invoice->city_val = $invoice->consignee_city ? $this->getAddress($invoice->consignee_city) : '';
......@@ -261,7 +271,7 @@ Class AddOrderController extends Controller
// 发票公司信息
if (in_array($invoice->inv_type, [3, 4])) {
$company_info = DB::connection('order')->table('lie_invoice_company')->where('com_name', $invoice->tax_title)->first();
$company_info = InvoiceCompanyModel::where('com_name', $invoice->tax_title)->first();
if ($company_info) {
$invoice->customer_en = $company_info->customer_en;
......@@ -283,7 +293,7 @@ Class AddOrderController extends Controller
$user_id = $request->input('user_id');
$inv_type = $request->input('inv_type');
$invoice = DB::connection('order')->table('lie_taxinfo')->where(['user_id'=>$user_id, 'inv_type'=>$inv_type])->select('tax_id', 'tax_title')->get();
$invoice = TaxInfoModel::where(['user_id'=>$user_id, 'inv_type'=>$inv_type])->select('tax_id', 'tax_title')->get();
return ['errcode' => 0, 'errmsg' => '', 'data' => $invoice];
}
......@@ -315,7 +325,7 @@ Class AddOrderController extends Controller
// 查询省市区
public function getAddress($id)
{
$addr = DB::connection('order')->table('lie_region')->where('region_id', $id)->select('region_name')->first();
$addr = RegionModel::where('region_id', $id)->select('region_name')->first();
return $addr ? $addr->region_name : '未匹配到ID:'.$id;
}
......@@ -328,11 +338,11 @@ Class AddOrderController extends Controller
$info['title'] = '新增自营线下订单';
// 默认内部账号ID
$internal = DB::connection('order')->table('lie_user_main')->where('mobile', Config('website.internal-account'))->select('user_id')->first();
$internal = UserMainModel::where('mobile', Config('website.internal-account'))->select('user_id')->first();
$info['internal_uid'] = $internal->user_id;
// 默认内部账号收货地址
$address = DB::connection('order')->table('lie_user_address')->where(['user_id' => $info['internal_uid'], 'is_default' => 1])->first();
$address = UserAddressModel::where(['user_id' => $info['internal_uid'], 'is_default' => 1])->first();
$address->province_val = $this->getAddress($address->province);
$address->city_val = $this->getAddress($address->city);
......@@ -350,7 +360,7 @@ Class AddOrderController extends Controller
$intracode = DB::table('lie_intracode')->where('admin_id', $sale_id)->select('user_id')->first();
if (!empty($intracode)) {
$user = DB::connection('order')->table('lie_user_main')->where('user_id', $intracode->user_id)->select('mobile')->first();
$user = UserMainModel::where('user_id', $intracode->user_id)->select('mobile')->first();
$info['mobile'] = $user ? $user->mobile : '';
} else {
......@@ -551,7 +561,7 @@ Class AddOrderController extends Controller
$data['buyer_id'] = $CmsModel->getSaleId($buyer);
}
} else { // 修改交期
$goods_data = DB::connection('order')->table('lie_shopping_cart')->where('cart_id', $cart_id)->value('goods_data');
$goods_data = ShoppingCartModel::where('cart_id', $cart_id)->value('goods_data');
if (!$goods_data) {
$goods_data['delivery_time'] = $delivery_time;
......@@ -563,7 +573,7 @@ Class AddOrderController extends Controller
$data['goods_data'] = json_encode($goods_data);
}
$res = DB::connection('order')->table('lie_shopping_cart')->where('cart_id', $cart_id)->update($data);
$res = ShoppingCartModel::where('cart_id', $cart_id)->update($data);
if ($res === false) return ['errcode' => -1, 'errmsg' => '修改失败'];
......@@ -773,10 +783,10 @@ Class AddOrderController extends Controller
$info['type'] = $type;
$info['is_quiry'] = $request->input('is_quiry', '');
$order = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->first();
$order = OrderModel::where('order_id', $order_id)->first();
if ($type != 3) {
$user = DB::connection('order')->table('lie_user_main')->where('user_id', $order->user_id)->select('mobile')->first();
$user = UserMainModel::where('user_id', $order->user_id)->select('mobile')->first();
$info['user_info'] = $user;
}
......@@ -803,7 +813,7 @@ Class AddOrderController extends Controller
$response = json_decode(curlApi($url, $data), true);
if ($response['err_code'] == 0) {
$orderInfo = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->first();
$orderInfo = OrderModel::where('order_id', $order_id)->first();
DB::beginTransaction();
try {
......@@ -814,7 +824,7 @@ Class AddOrderController extends Controller
$price['price'] = '-'.$orderInfo->order_amount;
$price['create_time'] = time();
$priceAdd = DB::connection('order')->table('lie_order_price')->insert($price);
$priceAdd = OrderPriceModel::insert($price);
// 添加付款记录
$pay['user_id'] = $orderInfo->user_id;
......@@ -828,10 +838,10 @@ Class AddOrderController extends Controller
$pay['create_time'] = time();
$pay['pay_time'] = time();
$payLog = DB::connection('order')->table('lie_pay_log')->insert($pay);
$payLog = PayLogModel::insert($pay);
// 待发货状态
$update = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->update(['status' => $status, 'pay_time' => time(), 'wms_syn' => 1]);
$update = OrderModel::where('order_id', $order_id)->update(['status' => $status, 'pay_time' => time(), 'wms_syn' => 1]);
if ($update && $priceAdd && $payLog) {
DB::commit();
......@@ -862,13 +872,14 @@ Class AddOrderController extends Controller
}
// 操作记录
$log['order_id'] = $order_id;
$log['operator_id'] = $request->user->userId;
$log['order_id'] = $order_id;
$log['operator_id'] = $request->user->userId;
$log['operator_type'] = 2;
$log['event'] = $event;
$log['ip'] = get_client_ip();
$log['create_time'] = time();
$actionLog = DB::connection('order')->table('lie_order_action_log')->insert($log);
$log['event'] = $event;
$log['ip'] = get_client_ip();
$log['create_time'] = time();
$actionLog = OrderActionLogModel::insert($log);
if (!$actionLog){
errorLog(Error::E_ADD_FAILED, '添加操作记录失败');
......@@ -1093,7 +1104,7 @@ Class AddOrderController extends Controller
$data['operator_id'] = $request->user->userId;
if ($goods_type == 1 && !$add_type) {
$temp_save_info = DB::connection('order')->table('lie_order_extend')->where('order_id', $data['order_id'])->value('temp_save_info');
$temp_save_info = OrderExtendModel::where('order_id', $data['order_id'])->value('temp_save_info');
// 获取临时保存信息
if ($temp_save_info) {
......
......@@ -5,7 +5,8 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Error;
use DB;
use App\Http\Model\UserActionLogModel;
use App\Model\RegionModel;
use App\Model\UserAddressModel;
class AddressController extends Controller
{
......@@ -58,7 +59,7 @@ class AddressController extends Controller
// 地址
public function getRegion($region_id)
{
$region = DB::connection('order')->table('lie_region')->where('region_id', $region_id)->select('region_name')->first();
$region = RegionModel::where('region_id', $region_id)->select('region_name')->first();
return $region ? $region->region_name : '';
}
......@@ -69,7 +70,7 @@ class AddressController extends Controller
if ($request->isMethod('post')) {
$address_id = $request->input('address_id');
$info = DB::connection('order')->table('lie_user_address')->where('address_id', $address_id)->first();
$info = UserAddressModel::where('address_id', $address_id)->first();
if (empty($info)) return ['errcode' => Error::E_NOT_EXISTS, 'errmsg' => '未找到'];
......@@ -160,15 +161,13 @@ class AddressController extends Controller
}
if ($map['user_id'] && isset($map['address_type'])) {
$addressList = DB::connection('order')->table('lie_user_address')->where($map)->get();
$addressList = UserAddressModel::where($map)->get();
}
if(!empty($addressList) && is_array($addressList)) {
$region = array();
foreach ($addressList as &$val) {
$region = DB::connection('order')
->table('lie_region')
->whereIn('region_id', [$val->province, $val->city, $val->district])
$region = RegionModel::whereIn('region_id', [$val->province, $val->city, $val->district])
->select('region_id', 'region_name')
->get();
......
......@@ -18,20 +18,23 @@ use App\Model\OrderExtendModel;
use App\Model\OrderItemsModel;
use App\Model\OrderItemsTrackModel;
use App\Model\OrderItemsTrackingModel;
use App\Model\UserSampleApplyModel;
use App\Model\OrderActionLogModel;
use App\Model\UserSampleInviteModel;
use App\Model\UserGroupModel;
use App\Model\UserMainModel;
use App\Model\BrandBlackListModel;
use App\Model\PayExtendModel;
use Illuminate\Support\Facades\Redis;
use App\Model\ShoppingCartModel;
use App\Model\OrderServiceModel;
use App\Model\OrderServiceItemsModel;
use App\Model\OrderServiceLogModel;
use App\Model\OrderRefundModel;
use App\Model\OrderRefundLogModel;
use App\Model\BrandBlackListModel;
use App\Model\PayExtendModel;
use App\Model\UserMainModel;
use App\Model\UserAddressModel;
use App\Model\TaxInfoModel;
use App\Model\RegionModel;
use App\Model\UserGroupModel;
use App\Model\UserSampleApplyModel;
use App\Model\UserSampleInviteModel;
use Illuminate\Support\Facades\Redis;
use DB;
use App\Model\Frq\InquiryItemsReportModel;
......@@ -524,7 +527,7 @@ class ApiController extends Controller
if ($account) {
$field = preg_match('/@/', $account) ? 'email' : 'mobile';
$user_id = DB::connection('order')->table('lie_user_main')->where($field, $account)->value('user_id');
$user_id = UserMainModel::where($field, $account)->value('user_id');
}
// 公司和联系方式都存在
......@@ -599,7 +602,7 @@ class ApiController extends Controller
$where['user_id'] = $user_id;
$where['inv_type'] = 2;
$tax_info = DB::connection('order')->table('lie_taxinfo')->where($where)->select('tax_title', 'tax_id')->get();
$tax_info = TaxInfoModel::where($where)->select('tax_title', 'tax_id')->get();
$this->Export(0, '', $tax_info);
}
......@@ -613,7 +616,7 @@ class ApiController extends Controller
$map['tax_title'] = $com_info->com_name;
$map['user_id'] = $user_id;
$map['inv_type'] = $invoice_type;
$invoice = DB::connection('order')->table('lie_taxinfo')->where($map)->first();
$invoice = TaxInfoModel::where($map)->first();
if (!$invoice) $this->Export(-1, '未找到发票信息');
$tax_info['tax_id'] = isset($invoice) ? $invoice->tax_id : 0;
......@@ -644,7 +647,7 @@ class ApiController extends Controller
$map['user_id'] = $user_id;
$map['address_type'] = 0;
$address = DB::connection('order')->table('lie_user_address')->where($map)->get();
$address = UserAddressModel::where($map)->get();
if (empty($address)) $this->Export(-1, '未获取到用户收货地址');
foreach ($address as &$v) {
......@@ -661,7 +664,7 @@ class ApiController extends Controller
// 查询省市区
public function getAddress($id)
{
return DB::connection('order')->table('lie_region')->where('region_id', $id)->value('region_name');
return RegionModel::where('region_id', $id)->value('region_name');
}
// 导入销售报价物料
......
......@@ -12,20 +12,29 @@ use App\Http\Controllers\PermController;
use Illuminate\Support\Facades\Redis;
use App\Http\Error;
use Excel;
use App\Model\UserMainModel;
use App\Model\UserCompanyModel;
use App\Model\CmsModel;
use App\Model\QueuedModel;
use App\Model\OrderModel;
use App\Model\OrderExtendModel;
use App\Model\UserMainModel;
use App\Model\OrderPriceModel;
use App\Model\OrderAddressModel;
use App\Model\OrderActionLogModel;
use App\Model\OrderReturnModel;
use App\Model\OrderItemsTrackModel;
use App\Model\OrderItemsTrackingModel;
use App\Model\CmsModel;
use App\Model\QueuedModel;
use App\Model\PayLogModel;
use App\Model\ErpPayLogModel;
use App\Model\PayExtendModel;
use App\Model\OrderPurPriceModel;
use App\Model\OrderShippingModel;
use App\Model\OrderInvoiceModel;
use App\Model\OrderServiceModel;
use App\Model\OrderServiceItemsModel;
use App\Model\RemovalItemsModel;
use App\Model\OrderReturnItemsModel;
use App\Model\ShippingModel;
use App\Model\CrmModel;
use Session;
use Hprose\Http\Client;
......@@ -33,14 +42,7 @@ use Hprose\Http\Client;
// 获取订单优惠券金额
function getCoupon($order_id)
{
$price = DB::connection('order')
->table('lie_order_price')
->where(['order_id' => $order_id, 'price_type' => -4])
->first();
if (!$price) return null;
return $price->price;
return OrderPriceModel::where(['order_id' => $order_id, 'price_type' => -4])->value('price');
}
// 获取会员账号
......@@ -48,8 +50,7 @@ function getAccountName($user_id)
{
if (!$user_id) return false;
$userMainModel = new UserMainModel();
$user = $userMainModel->where('user_id', $user_id)->select('mobile', 'email')->first();
$user = UserMainModel::where('user_id', $user_id)->select('mobile', 'email')->first();
if (!$user) return false;
......@@ -59,13 +60,9 @@ function getAccountName($user_id)
// 获取支付名称
function getPayName($order_id)
{
$payLog = DB::connection('order')
->table('lie_pay_log')
->where(['order_id' => $order_id])
->select('pay_name')
->get();
$payLog = PayLogModel::where(['order_id' => $order_id])->select('pay_name')->get();
if (!$payLog) return false;
if ($payLog->isEmpty()) return false;
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
......@@ -76,9 +73,7 @@ function getPayName($order_id)
function getShipping($order_id, $shipping_type=1)
{
$shipping = DB::connection('order')
->table('lie_order_shipping')
->where(['order_id' => $order_id, 'shipping_type' => $shipping_type])
$shipping = OrderShippingModel::where(['order_id' => $order_id, 'shipping_type' => $shipping_type])
->select('shipping_no', 'status')
->orderBy('order_shipping_id')
->get();
......@@ -90,15 +85,7 @@ function getShipping($order_id, $shipping_type=1)
function getInvoiceStatus($order_id)
{
$invoice = DB::connection('order')
->table('lie_order_invoice')
->where(['order_id' => $order_id])
->select('invoice_status')
->first();
if (!$invoice) return false;
return $invoice->invoice_status;
return OrderInvoiceModel::where(['order_id' => $order_id])->value('invoice_status');
}
// 发票抬头 -> 合同公司
......@@ -106,7 +93,7 @@ function getCompanyName($order_id, $user_id)
{
if (!$user_id) return false;
$tax_title = DB::connection('order')->table('lie_order_invoice')->where('order_id', $order_id)->where('inv_type', '<>', 1)->value('tax_title');
$tax_title = OrderInvoiceModel::where('order_id', $order_id)->where('inv_type', '<>', 1)->value('tax_title');
if ($tax_title) return $tax_title;
// $contract_com_name = DB::connection('order')->table('lie_order_extend')->where('order_id', $order_id)->value('contract_com_name');
......@@ -114,7 +101,7 @@ function getCompanyName($order_id, $user_id)
// return false;
$com_name = DB::connection('order')->table('lie_user_company')->where('user_id', $user_id)->value('com_name');
$com_name = UserCompanyModel::where('user_id', $user_id)->value('com_name');
if ($com_name) return $com_name;
return false;
......@@ -160,7 +147,7 @@ function isNewClient($order_goods_type, $user_id, $create_time)
// $order = DB::connection('order')->table('lie_order')->where('order_goods_type', $order_goods_type)->where('user_id', $user_id)->whereBetween('create_time', [$half_year_time, $create_time-1])->get();
$user = DB::connection('order')->table('lie_user_main')->where('user_id', $user_id)->first();
$user = UserMainModel::where('user_id', $user_id)->first();
// return empty($order) && empty($user->client_source) ? true : false;
return $user && $user->is_new == 0 && empty($user->client_source) ? true : false;
......@@ -171,9 +158,7 @@ function clientSource($user_id)
{
if (!$user_id) return false;
$user = DB::connection('order')->table('lie_user_main')->where('user_id', $user_id)->select('client_source')->first();
return $user ? $user->client_source : '';
return UserMainModel::where('user_id', $user_id)->value('client_source');
}
// 获取自营商品型号
......@@ -188,7 +173,7 @@ function getGoodsName($goods_id)
function getOrderSource($order_id, $order_type=1, $order_goods_type=1)
{
if ($order_type == 1) {
$order_source = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->value('order_source');
$order_source = OrderModel::where('order_id', $order_id)->value('order_source');
if (preg_match('/pf=1/', $order_source)) {
$source = 'PC端';
......@@ -246,11 +231,7 @@ function handleOrderSource($order_source)
// 获取订单收货人
function getOrderAddress($order_id)
{
$order = DB::connection('order')->table('lie_order_address')->where('order_id', $order_id)->select('consignee')->first();
if (!$order) return false;
return $order->consignee;
return OrderAddressModel::where('order_id', $order_id)->value('consignee');
}
// 获取渠道名称
......@@ -310,7 +291,7 @@ function getOrderExtend($order_id, $field="*", $where=array())
$map = array_merge($map, $where);
}
$extend = DB::connection('order')->table('lie_order_extend')->where($map)->select($field)->first();
$extend = OrderExtendModel::where($map)->select($field)->first();
return $extend;
}
......@@ -803,7 +784,7 @@ Class OrderController extends Controller
// 详情页自营其他数据
public function selfOtherData(&$info, $order_id)
{
$shipping = DB::connection('order')->table('lie_shipping')->select('shipping_id', 'shipping_name')->get();
$shipping = ShippingModel::select('shipping_id', 'shipping_name')->get();
$info['shippings'] = [];
......@@ -815,7 +796,7 @@ Class OrderController extends Controller
$info['shippings'] = $shippingInfo;
}
$extend = DB::connection('order')->table('lie_order_extend')->where(['order_id' => $order_id, 'order_type' => 3])->first(); // 自营线下订单
$extend = OrderExtendModel::where(['order_id' => $order_id, 'order_type' => 3])->first(); // 自营线下订单
$info['extend'] = $extend ? $extend : '';
}
......@@ -1132,7 +1113,7 @@ Class OrderController extends Controller
$order_id = $request->input('order_id');
// 调价失败临时表状态更改
$order_temp = DB::connection('order')->table('lie_order_extend')->where(['order_id' => $order_id])->update(['status' => -1]);
$order_temp = OrderExtendModel::where(['order_id' => $order_id])->update(['status' => -1]);
if (!$order_temp) {
errorLog(Error::E_UPDATE_FAILED, '驳回失败');
......@@ -1305,37 +1286,6 @@ Class OrderController extends Controller
}
}
// 审核不通过
// public function ajaxCheck(Request $request)
// {
// if($request->isMethod('post')){
// $order_id = $request->input('order_id', ''); //订单号
// $sale_id = $request->input('sale_id', null); //对应销售
// $operator_id = $request->user->userId;
// $cancel_reason = $request->input('cancel_reason', '');
// if (!isset($sale_id)) {
// return array('errcode'=>1, 'errmsg'=>'请选择订单业务员!');
// }
// if (!$order_id) {
// return array('errcode'=>1, 'errmsg'=>'订单参数有误!');
// }
// //用于后台订单审核
// $url = Config('website.api_domain').'order/cancel';
// $check['k1'] = time();
// $check['k2'] = md5(md5($check['k1']).'fh6y5t4rr351d2c3bryi');
// $resData = array("cancel_reason"=>$cancel_reason, "order_id"=>$order_id, 'sale_id'=>$sale_id, "pf"=>1, "k1"=>$check['k1'], "k2"=>$check['k2'], 'operator_id'=>$operator_id, 'type' => 3);
// $temp = json_decode(curlApi($url, $resData, "POST"), true);
// return array('errcode'=>$temp['err_code'],'errmsg'=>$temp['err_msg']);
// }
// }
// 对账
public function checkPay(Request $request, $id)
{
......@@ -1371,7 +1321,7 @@ Class OrderController extends Controller
} else {
$payLog['is_paid'] = 2;
if (DB::connection('order')->table('lie_pay_log')->where(['order_id'=>$order_id, 'pay_type'=>2])->update($payLog)) {
if (PayLogModel::where(['order_id'=>$order_id, 'pay_type'=>2])->update($payLog)) {
return array('errcode'=>0,'errmsg'=>'操作成功');
}
}
......@@ -1518,11 +1468,11 @@ Class OrderController extends Controller
$map['rec_id'] = $v['rec_id'];
$map['goods_id'] = $v['goods_id'];
// 获取出库数量
$removal = DB::connection('order')->table('lie_removal_items')->where($map)->select('removal_number')->first();
$removal = RemovalItemsModel::where($map)->select('removal_number')->first();
$v['removal_number'] = $removal ? $removal->removal_number : 0;
// 获取已申请退货数量
$v['already_return_num'] = DB::connection('order')->table('lie_order_return_items')->where($map)->sum('return_num');
$v['already_return_num'] = OrderReturnItemsModel::where($map)->sum('return_num');
}
return view('detail', $info);
......@@ -1684,7 +1634,7 @@ Class OrderController extends Controller
$info = $this->orderDetail($request, $id);
$this->pageHeader($request, $info, '发货', ["title" => '发货', "href" => '#']);
$shippings = DB::connection('order')->table('lie_shipping')->where(['enabled'=>1,'is_order'=>1])->get();//获取配送方式
$shippings = ShippingModel::where(['enabled'=>1,'is_order'=>1])->get();//获取配送方式
$ship_type = [];
foreach ($shippings as $key => $value) {
......@@ -1737,7 +1687,7 @@ Class OrderController extends Controller
}
//物流信息
$shippings = DB::connection('order')->table('lie_shipping')->where(['enabled'=>1,'is_invoice'=>1])->get();
$shippings = ShippingModel::where(['enabled'=>1,'is_invoice'=>1])->get();
$shippingArr = [];
foreach ($shippings as $key => $value) {
......@@ -1779,10 +1729,10 @@ Class OrderController extends Controller
// }
// 获取操作记录
$actionLog = DB::connection('order')->table('lie_order_action_log')->where('order_id', $id)->orderBy('create_time', 'DESC')->orderBy('log_id', 'DESC')->get();
$actionLog = OrderActionLogModel::where('order_id', $id)->orderBy('create_time', 'DESC')->orderBy('log_id', 'DESC')->get();
// 获取ERP支付记录
$erpPayLog = DB::connection('order')->table('lie_erp_pay_log')->where('order_id', $id)->orderBy('create_time', 'DESC')->orderBy('log_id', 'DESC')->get();
$erpPayLog = ErpPayLogModel::where('order_id', $id)->orderBy('create_time', 'DESC')->orderBy('log_id', 'DESC')->get();
$response = [
// 'user_mobile' => $mobile,
......@@ -1992,9 +1942,7 @@ Class OrderController extends Controller
*/
public function checkOrderSendSms()
{
$order = DB::connection('order')
->table('lie_order')
->where('order_goods_type', '=', 1)
$order = OrderModel::where('order_goods_type', '=', 1)
->where('status', '=', 2)
// ->whereNotIn('user_id', $this->testMobile())
->where('is_type', '=', 0)
......@@ -2061,9 +2009,9 @@ Class OrderController extends Controller
{
$time = strtotime(date('Y-m-d', time())); // 当天0点
$order = DB::connection('order')
->table('lie_order')
->where('order_goods_type', '=', 1)
$OrderModel = new OrderModel;
$order = $OrderModel->where('order_goods_type', '=', 1)
->where('order_pay_type', '<>', 3) // 过滤账期订单
->where('status', '=', 2)
// ->whereNotIn('user_id', $this->testMobile())
......@@ -2077,10 +2025,7 @@ Class OrderController extends Controller
foreach ($order as $v) {
// 到达付款时间后自动取消订单
if ($v->pay_time <= time()) {
$update = DB::connection('order')
->table('lie_order')
->where('order_id', '=', $v->order_id)
->update(['status' => -1, 'pay_time' => 0, 'cancel_time' => time()]);
$update = $OrderModel->where('order_id', '=', $v->order_id)->update(['status' => -1, 'pay_time' => 0, 'cancel_time' => time()]);
if ($update) {
// 操作记录
......@@ -2109,11 +2054,11 @@ Class OrderController extends Controller
return ['errcode'=>Error::E_NOT_EXISTS, 'errmsg'=>'参数不存在'];
}
$order = DB::connection('order')->table('lie_order')->where('order_id', '=', $order_id)->select('pay_time')->first();
$order = OrderModel::where('order_id', '=', $order_id)->select('pay_time')->first();
$delay_time = $order->pay_time + $delay_time * 86400;
$update = DB::connection('order')->table('lie_order')->where('order_id', '=', $order_id)->update(['pay_time'=>$delay_time]);
$update = OrderModel::where('order_id', '=', $order_id)->update(['pay_time'=>$delay_time]);
if (!$update) {
errorLog(Error::E_UPDATE_FAILED, '延长失败');
......@@ -2163,7 +2108,7 @@ Class OrderController extends Controller
$data['contract_link_tel'] = $request->input('contract_link_tel', '');
DB::connection('order')->transaction(function() use ($request, $order_id, $data) {
DB::connection('order')->table('lie_order_extend')->where('order_id', $order_id)->update($data);
OrderExtendModel::where('order_id', $order_id)->update($data);
$OrderActionLogModel = new OrderActionLogModel();
$OrderActionLogModel->addLog($order_id, $request->user->userId, 2, '编辑合同乙方信息'); // 操作记录
......@@ -2181,8 +2126,8 @@ Class OrderController extends Controller
$data['upload_contract_url'] = $request->input('url');
DB::connection('order')->transaction(function() use ($request, $order_id, $data) {
DB::connection('order')->table('lie_order')->where('order_id', $order_id)->update(['erp_syn'=>1]); // 标记ERP同步
DB::connection('order')->table('lie_order_extend')->where('order_id', $order_id)->update($data);
OrderModel::where('order_id', $order_id)->update(['erp_syn'=>1]); // 标记ERP同步
OrderExtendModel::where('order_id', $order_id)->update($data);
$OrderActionLogModel = new OrderActionLogModel();
$OrderActionLogModel->addLog($order_id, $request->user->userId, 2, '回传合同'); // 操作记录
......@@ -2220,17 +2165,13 @@ Class OrderController extends Controller
$testMobile = $userMainModel->testMobile();
// 订单数量
$halfCount = DB::connection('order')->table('lie_order')
// ->where('order_goods_type', 1)
// ->where('order_type', 1)
->whereNotIn('user_id', $testMobile)
$halfCount = OrderModel::whereNotIn('user_id', $testMobile)
->where('is_type', 0)
->whereBetween('create_time', [$half, $current])
->count();
echo '半年订单数:'.$halfCount.'<br>';
$yearCount = DB::connection('order')->table('lie_order')
->whereNotIn('user_id', $testMobile)
$yearCount = OrderModel::whereNotIn('user_id', $testMobile)
->where('is_type', 0)
->whereBetween('create_time', [$year, $current])
->count();
......@@ -2285,7 +2226,7 @@ Class OrderController extends Controller
// 查找用户订单数,并更新用户表和订单扩展表
$subQuery = OrderModel::where('is_type', '=', 0)->where('status', '<>', -1)->orderBy('order_id');
DB::connection('order')->table('lie_order_extend')->update(['is_new' => 0]); // 是否新订单恢复默认值0
OrderExtendModel::update(['is_new' => 0]); // 是否新订单恢复默认值0
OrderModel::from(DB::raw("({$subQuery->toSql()}) as sub"))
->mergeBindings($subQuery->getQuery())
......@@ -2304,17 +2245,17 @@ Class OrderController extends Controller
}
// 更新用户
DB::connection('order')->table('lie_user_main')->where('user_id', $v->user_id)->update($new_user);
UserMainModel::where('user_id', $v->user_id)->update($new_user);
$extend = DB::connection('order')->table('lie_order_extend')->where('order_id', $v->order_id)->first();
$extend = OrderExtendModel::where('order_id', $v->order_id)->first();
if ($extend) {
// 更新订单
DB::connection('order')->table('lie_order_extend')->where('order_id', $v->order_id)->update($new_order);
OrderExtendModel::where('order_id', $v->order_id)->update($new_order);
} else {
// 创建
$new_order['order_id'] = $v->order_id;
DB::connection('order')->table('lie_order_extend')->insert($new_order);
OrderExtendModel::insert($new_order);
}
}
});
......
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\OrderModel;
use App\Model\OrderRefundModel;
use App\Model\OrderRefundItemsModel;
use DB;
use App\Http\Page;
use App\Model\UserMainModel;
// 获取会员账号
function getAccountName($user_id)
{
if (!$user_id) return false;
$userMainModel = new UserMainModel;
$user = $userMainModel->find($user_id);
if (!$user) return false;
return $user->mobile ? $user->mobile : $user->email;
}
// 获取订单金额
function getOrderAmount($order_id)
{
if (!$order_id) return false;
$OrderModel = new OrderModel;
$order = $OrderModel->find($order_id);
if (!$order) return false;
return $order->order_amount;
}
// 获取支付名称
function getPayName($order_id)
{
$payLog = DB::connection('order')
->table('lie_pay_log')
->where(['order_id' => $order_id])
->select('pay_name')
->get();
if (!empty($payLog)) {
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
}
return implode(',', $payName);
}
return false;
}
class RefundController extends Controller
{
// 页面用户、菜单信息
public function getPageInfo(Request $request)
{
$uri = '/' . $request->path();
if ($request->path() == '/') $uri = '/list';
$username = $request->user->email;
$useremail= $request->user->email;
// 菜单
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
$menus = [];
if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
$menus = [];
$perm = new PermController;
// 用户角色
$role = $perm->getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = $perm->getPermMenu($menus, $request->user->userId);
}
$userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限
$data = [
'header' => $request->user->header,
'uri' => $uri,
'username' => $username,
'useremail' => $useremail,
'menus' => $menus,
'userPerms' => $userPerms,
'role' => $role,
];
return $data;
}
// 联营退款列表
public function jointRefundList(Request $request)
{
$info = $this->refundList($request, 1);
return view('refundlist', $info);
}
// 自营退款列表
public function selfRefundList(Request $request)
{
$info = $this->refundList($request, 2);
return view('refundlist', $info);
}
// 退款申请列表
public function refundList(Request $request, $type)
{
$info = $this->getPageInfo($request);
$info['title'] = $type == 1 ? '联营退款申请列表' : '自营退款申请列表';
$map['refund_sn'] = $request->input('refund_sn', '');
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['is_refund'] = $request->input('is_refund', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_goods_type'] = $type; // 类型
//获取订单列表
$url = Config('website.api_domain').'refund/getRefundOrderList';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$data['p'] = $request->input('p', 1); // 当前页码
$data['size'] = 10; // 当前页条数
$data['map'] = $map;
$response = json_decode(curlApi($url, $data), true);
// 分页
$page = new Page($response['data']['count'], 10);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show = $page->show();
$info['condition'] = $map;
$info['list'] = $response['data']['data'];
$info['count'] = $response['data']['count'];
$info['page'] = $show;
return $info;
}
// 联营退款导出
public function refundExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->jointExport($request);
}
// 自营退款导出
public function refundSelfExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->selfExport($request);
}
// 退货详情
public function refundDetails(Request $request, $id)
{
$info = $this->getPageInfo($request);
$OrderRefundModel = new OrderRefundModel();
$info['refund'] = $OrderRefundModel->find($id);
$info['refundItems'] = $OrderRefundModel->find($id)->hasManyRefundItems;
if ($info['refund']['order_goods_type'] == 1) {
$title = '联营订单';
$refund_url = '/refund_order';
} else {
$title = '自营订单';
$refund_url = '/refund_self_order';
}
$info['title'] = '订单退货详情';
$info['paths'] = [["title" => $title, "href" => '#'], ["title" => '退款申请列表', "href" => $refund_url], ["title" => '订单退货详情', "href" => '#']];
return view('refundDetails', $info);
}
// 钱包退款
public function walletRefund(Request $request, $id)
{
// 获取退款单
// $refund = DB::connection('order')->table('lie_order_refund')->where('refund_id', $id)->first();
if (!$id) echo '未获取到退款单';
$data['refund_id'] = $id;
// $data['refund_amount'] = number_format($refund->pay_amount - $refund->price_fall, 2); // 最終退款金額
$data['pay_code'] = 'unionpay';
$url = Config('website.api_domain').'refund/recharge';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$temp = curlApi($url, $data, "POST");
if (!$temp) echo '未获取到退款地址';
echo $temp;
}
// 自营取消退款申请
public function cancelSelfRefund(Request $request)
{
$refund_id = $request->input('refund_id');
$update = DB::connection('order')->table('lie_order_refund')->where('refund_id', $refund_id)->update(['status' => -1]);
if (!$update) return ['errcode' => 1, 'errmsg' => '取消申请失败'];
return ['errcode' => 0, 'errmsg' => '取消申请成功'];
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Page;
use App\Http\Controllers\Controller;
use App\Model\UserMainModel;
use App\Model\OrderModel;
use App\Model\PayLogModel;
use App\Model\OrderRefundModel;
use App\Model\OrderRefundItemsModel;
use DB;
// 获取会员账号
function getAccountName($user_id)
{
if (!$user_id) return false;
$userMainModel = new UserMainModel;
$user = $userMainModel->find($user_id);
if (!$user) return false;
return $user->mobile ? $user->mobile : $user->email;
}
// 获取订单金额
function getOrderAmount($order_id)
{
if (!$order_id) return false;
$OrderModel = new OrderModel;
$order = $OrderModel->find($order_id);
if (!$order) return false;
return $order->order_amount;
}
// 获取支付名称
function getPayName($order_id)
{
$payLog = PayLogModel::where(['order_id' => $order_id])->select('pay_name')->get();
if ($payLog->isEmpty()) return false;
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
}
return implode(',', $payName);
}
class RefundController extends Controller
{
// 页面用户、菜单信息
public function getPageInfo(Request $request)
{
$uri = '/' . $request->path();
if ($request->path() == '/') $uri = '/list';
$username = $request->user->email;
$useremail= $request->user->email;
// 菜单
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
$menus = [];
if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
$menus = [];
$perm = new PermController;
// 用户角色
$role = $perm->getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = $perm->getPermMenu($menus, $request->user->userId);
}
$userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限
$data = [
'header' => $request->user->header,
'uri' => $uri,
'username' => $username,
'useremail' => $useremail,
'menus' => $menus,
'userPerms' => $userPerms,
'role' => $role,
];
return $data;
}
// 联营退款列表
public function jointRefundList(Request $request)
{
$info = $this->refundList($request, 1);
return view('refundlist', $info);
}
// 自营退款列表
public function selfRefundList(Request $request)
{
$info = $this->refundList($request, 2);
return view('refundlist', $info);
}
// 退款申请列表
public function refundList(Request $request, $type)
{
$info = $this->getPageInfo($request);
$info['title'] = $type == 1 ? '联营退款申请列表' : '自营退款申请列表';
$map['refund_sn'] = $request->input('refund_sn', '');
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['is_refund'] = $request->input('is_refund', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_goods_type'] = $type; // 类型
//获取订单列表
$url = Config('website.api_domain').'refund/getRefundOrderList';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$data['p'] = $request->input('p', 1); // 当前页码
$data['size'] = 10; // 当前页条数
$data['map'] = $map;
$response = json_decode(curlApi($url, $data), true);
// 分页
$page = new Page($response['data']['count'], 10);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show = $page->show();
$info['condition'] = $map;
$info['list'] = $response['data']['data'];
$info['count'] = $response['data']['count'];
$info['page'] = $show;
return $info;
}
// 联营退款导出
public function refundExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->jointExport($request);
}
// 自营退款导出
public function refundSelfExport(Request $request)
{
$refundModel = new OrderRefundModel();
return $refundModel->selfExport($request);
}
// 退货详情
public function refundDetails(Request $request, $id)
{
$info = $this->getPageInfo($request);
$OrderRefundModel = new OrderRefundModel();
$info['refund'] = $OrderRefundModel->find($id);
$info['refundItems'] = $OrderRefundModel->find($id)->hasManyRefundItems;
if ($info['refund']['order_goods_type'] == 1) {
$title = '联营订单';
$refund_url = '/refund_order';
} else {
$title = '自营订单';
$refund_url = '/refund_self_order';
}
$info['title'] = '订单退货详情';
$info['paths'] = [["title" => $title, "href" => '#'], ["title" => '退款申请列表', "href" => $refund_url], ["title" => '订单退货详情', "href" => '#']];
return view('refundDetails', $info);
}
// 钱包退款
public function walletRefund(Request $request, $id)
{
// 获取退款单
// $refund = DB::connection('order')->table('lie_order_refund')->where('refund_id', $id)->first();
if (!$id) echo '未获取到退款单';
$data['refund_id'] = $id;
// $data['refund_amount'] = number_format($refund->pay_amount - $refund->price_fall, 2); // 最終退款金額
$data['pay_code'] = 'unionpay';
$url = Config('website.api_domain').'refund/recharge';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$temp = curlApi($url, $data, "POST");
if (!$temp) echo '未获取到退款地址';
echo $temp;
}
// 自营取消退款申请
public function cancelSelfRefund(Request $request)
{
$refund_id = $request->input('refund_id');
$update = OrderRefundModel::where('refund_id', $refund_id)->update(['status' => -1]);
if (!$update) return ['errcode' => 1, 'errmsg' => '取消申请失败'];
return ['errcode' => 0, 'errmsg' => '取消申请成功'];
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Support\Facades\Redis as Redis;
use App\Model\RegionModel;
class RegionController extends Controller
{
public function getAll()
{
$provinces = array(); $citys = array(); $towns = array();
$list = DB::connection('order')->table('lie_region')->orderBy('region_id', 'asc')->get();
foreach (@$list as $val) {
if (!$val->parent_id) continue;
switch ($val->region_type) {
case 1:
$provinces[$val->parent_id]['parent_id'] = $val->parent_id;
$provinces[$val->parent_id]['children'][] = $val;
break;
case 2:
$citys[$val->parent_id]['parent_id'] = $val->parent_id;
$citys[$val->parent_id]['children'][] = $val;
break;
case 3:
$towns[$val->parent_id]['parent_id'] = $val->parent_id;
$towns[$val->parent_id]['children'][] = $val;
break;
}
}
return array(
'errcode'=>0,
'errmsg'=>'success',
'provinces'=> $provinces,
'citys'=> $citys,
'towns'=> $towns
);
}
//获取省市县名称
public function getRegionName($region_id)
{
if (empty($region_id)){
return "";
}
$list = DB::connection('order')->table('lie_region')->select("region_name")->where("region_id",$region_id)->get();
return !$list ? "" : current(objectToArray($list))['region_name'];
}
// 初始化地址缓存
public function cache()
{
$RegionModel = new RegionModel();
$province = $RegionModel->getRegion(1); // 获取省
S_str('oms:province', json_encode($province));
$city = $RegionModel->getRegion(2); // 获取城市
foreach($city as $c) {
S_hash('oms:city:'.$c['parent_id'], $c['region_id'], json_encode($c));
}
$district = $RegionModel->getRegion(3); // 获取区
foreach($district as $d) {
S_hash('oms:district:'.$d['parent_id'], $d['region_id'], json_encode($d));
}
echo '设置地址缓存成功';
}
// 清除缓存
public function clear()
{
Redis::del('oms:province');
Redis::del(Redis::keys('oms:city:*'));
Redis::del(Redis::keys('oms:district:*'));
echo '清除地址缓存成功';
}
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Support\Facades\Redis as Redis;
use App\Model\RegionModel;
class RegionController extends Controller
{
public function getAll()
{
$provinces = array(); $citys = array(); $towns = array();
$list = RegionModel::orderBy('region_id', 'asc')->get();
foreach (@$list as $val) {
if (!$val->parent_id) continue;
switch ($val->region_type) {
case 1:
$provinces[$val->parent_id]['parent_id'] = $val->parent_id;
$provinces[$val->parent_id]['children'][] = $val;
break;
case 2:
$citys[$val->parent_id]['parent_id'] = $val->parent_id;
$citys[$val->parent_id]['children'][] = $val;
break;
case 3:
$towns[$val->parent_id]['parent_id'] = $val->parent_id;
$towns[$val->parent_id]['children'][] = $val;
break;
}
}
return array(
'errcode'=>0,
'errmsg'=>'success',
'provinces'=> $provinces,
'citys'=> $citys,
'towns'=> $towns
);
}
//获取省市县名称
public function getRegionName($region_id)
{
if (empty($region_id)){
return "";
}
$list = RegionModel::select("region_name")->where("region_id",$region_id)->get();
return !$list ? "" : current(objectToArray($list))['region_name'];
}
// 初始化地址缓存
public function cache()
{
$RegionModel = new RegionModel();
$province = $RegionModel->getRegion(1); // 获取省
S_str('oms:province', json_encode($province));
$city = $RegionModel->getRegion(2); // 获取城市
foreach($city as $c) {
S_hash('oms:city:'.$c['parent_id'], $c['region_id'], json_encode($c));
}
$district = $RegionModel->getRegion(3); // 获取区
foreach($district as $d) {
S_hash('oms:district:'.$d['parent_id'], $d['region_id'], json_encode($d));
}
echo '设置地址缓存成功';
}
// 清除缓存
public function clear()
{
Redis::del('oms:province');
Redis::del(Redis::keys('oms:city:*'));
Redis::del(Redis::keys('oms:district:*'));
echo '清除地址缓存成功';
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\OrderModel;
use App\Model\OrderReturnModel;
use App\Model\OrderReturnItemsModel;
use DB;
use App\Http\Page;
use App\Model\UserMainModel;
use Illuminate\Support\Facades\Redis;
// 获取支付名称
function getPayName($order_id)
{
$payLog = DB::connection('order')
->table('lie_pay_log')
->where(['order_id' => $order_id])
->select('pay_name')
->get();
if (!empty($payLog)) {
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
}
return implode(',', $payName);
}
return false;
}
// 获取交易员名称
function getSalesName($sale_id)
{
if (!$sale_id) return false;
$user = DB::table('user_info')->where('userId', $sale_id)->select('name')->first();
return isset($user) ? $user->name : '';
}
// 获取物流名称
function getShippingName($shipping_id)
{
$shipping = DB::connection('order')->table('lie_shipping')->where('shipping_id', $shipping_id)->select('shipping_name')->first();
return $shipping ? $shipping->shipping_name : '';
}
class ReturnController extends Controller
{
// 页面用户、菜单信息
public function getPageInfo(Request $request)
{
$uri = '/' . $request->path();
if ($request->path() == '/') $uri = '/list';
$username = $request->user->email;
$useremail= $request->user->email;
// 菜单
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
$menus = [];
if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
$menus = [];
$perm = new PermController;
// 用户角色
$role = $perm->getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = $perm->getPermMenu($menus, $request->user->userId);
}
$userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限
$data = [
'header' => $request->user->header,
'uri' => $uri,
'username' => $username,
'useremail' => $useremail,
'menus' => $menus,
'userPerms' => $userPerms,
'role' => $role,
];
return $data;
}
// 联营退货列表
public function jointReturnList(Request $request)
{
$info = $this->ReturnList($request, 1);
return view('returnlist', $info);
}
// 自营退货列表
public function selfReturnList(Request $request)
{
$info = $this->returnList($request, 2);
return view('returnlist', $info);
}
// 退货申请列表
public function returnList(Request $request, $type)
{
$info = $this->getPageInfo($request);
$info['title'] = $type == 1 ? '联营退货申请列表' : '自营退货申请列表';
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['is_refund'] = $request->input('is_refund', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_goods_type'] = $type; // 类型
$map['sale_id'] = $request->input('sale_id', '');
// 非管理员、查看下级,只能看到自己的退货单
if ($info['role'] == 3) {
$map['create_uid'] = $request->user->userId;
}
if (!empty($map['sale_id'])) {
$map['create_uid'] = $map['sale_id'];
}
//获取订单列表
$url = Config('website.api_domain').'return/getReturnList';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$data['p'] = $request->input('p', 1); // 当前页码
$data['size'] = 10; // 当前页条数
$data['map'] = $map;
$response = json_decode(curlApi($url, $data), true);
// 分页
$page = new Page($response['data']['count'], 10);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show = $page->show();
// 获取配送方式
$shippings = DB::connection('order')->table('lie_shipping')->get();
$ship_type = [];
foreach ($shippings as $k => $v) {
$ship_type[$v->shipping_id] = $v->shipping_name;
}
$info['shippings'] = $ship_type;
$info['condition'] = $map;
$info['list'] = $response['data']['data'];
$info['count'] = $response['data']['count'];
$info['page'] = $show;
// $perm = new PermController;
// $joint_kefu = $perm->getRoleUsers($request, '客服');
// $self_kefu = $perm->getRoleUsers($request, '自营客服');
// $info['sale_list'] = array_merge($joint_kefu, $self_kefu);
$perm = new PermController;
$sale_list = $perm->getUserByDepartmentId(Config('perm_args.sales_department_id')); // 获取所有的销售
$info['sale_list'] = $sale_list;
return $info;
}
// 联营退货单导出
public function returnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->export($request);
}
// 自营退货单导出
public function selfReturnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->export($request);
}
// 退货详情
public function returnDetails(Request $request, $id)
{
$info = $this->getPageInfo($request);
$OrderReturnModel = new OrderReturnModel();
$info['return'] = $OrderReturnModel->find($id);
$info['returnItems'] = $OrderReturnModel->find($id)->hasManyReturnItems;
$info['returnLog'] = $OrderReturnModel->find($id)->hasManyReturnLog;
if ($info['return']['order_goods_type'] == 1) {
$title = '联营订单';
$return_url = '/return_list';
} else {
$title = '自营订单';
$return_url = '/self_return_list';
}
$info['title'] = '订单退货详情';
$info['paths'] = [["title" => $title, "href" => '#'], ["title" => '退货申请列表', "href" => $return_url], ["title" => '订单退货详情', "href" => '#']];
return view('returnDetails', $info);
}
// 退货单审核
public function returnCheck(Request $request)
{
if ($request->isMethod('post')) {
$OrderReturnModel = new OrderReturnModel();
return $OrderReturnModel->check($request);
}
}
// 退货物流信息
public function returnShipping(Request $request)
{
if ($request->isMethod('post')) {
$OrderReturnModel = new OrderReturnModel();
return $OrderReturnModel->shipping($request);
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use App\Http\Requests;
use App\Http\Page;
use App\Http\Controllers\Controller;
use App\Model\OrderModel;
use App\Model\OrderReturnModel;
use App\Model\OrderReturnItemsModel;
use App\Model\PayLogModel;
use App\Model\UserMainModel;
use App\Model\ShippingModel;
use DB;
// 获取支付名称
function getPayName($order_id)
{
$payLog = PayLogModel::where(['order_id' => $order_id])->select('pay_name')->get();
if ($payLog->isEmpty()) return false;
foreach ($payLog as $v) {
$payName[] = $v->pay_name;
}
return implode(',', $payName);
}
// 获取交易员名称
function getSalesName($sale_id)
{
if (!$sale_id) return false;
$user = DB::table('user_info')->where('userId', $sale_id)->select('name')->first();
return isset($user) ? $user->name : '';
}
// 获取物流名称
function getShippingName($shipping_id)
{
$shipping = ShippingModel::where('shipping_id', $shipping_id)->select('shipping_name')->first();
return $shipping ? $shipping->shipping_name : '';
}
class ReturnController extends Controller
{
// 页面用户、菜单信息
public function getPageInfo(Request $request)
{
$uri = '/' . $request->path();
if ($request->path() == '/') $uri = '/list';
$username = $request->user->email;
$useremail= $request->user->email;
// 菜单
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
$menus = [];
if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
$menus = [];
$perm = new PermController;
// 用户角色
$role = $perm->getUserRole($request);
// 获取权限菜单
if ($role != 1) {
$menus = $perm->getPermMenu($menus, $request->user->userId);
}
$userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限
$data = [
'header' => $request->user->header,
'uri' => $uri,
'username' => $username,
'useremail' => $useremail,
'menus' => $menus,
'userPerms' => $userPerms,
'role' => $role,
];
return $data;
}
// 联营退货列表
public function jointReturnList(Request $request)
{
$info = $this->ReturnList($request, 1);
return view('returnlist', $info);
}
// 自营退货列表
public function selfReturnList(Request $request)
{
$info = $this->returnList($request, 2);
return view('returnlist', $info);
}
// 退货申请列表
public function returnList(Request $request, $type)
{
$info = $this->getPageInfo($request);
$info['title'] = $type == 1 ? '联营退货申请列表' : '自营退货申请列表';
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['is_refund'] = $request->input('is_refund', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_goods_type'] = $type; // 类型
$map['sale_id'] = $request->input('sale_id', '');
// 非管理员、查看下级,只能看到自己的退货单
if ($info['role'] == 3) {
$map['create_uid'] = $request->user->userId;
}
if (!empty($map['sale_id'])) {
$map['create_uid'] = $map['sale_id'];
}
//获取订单列表
$url = Config('website.api_domain').'return/getReturnList';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$data['p'] = $request->input('p', 1); // 当前页码
$data['size'] = 10; // 当前页条数
$data['map'] = $map;
$response = json_decode(curlApi($url, $data), true);
// 分页
$page = new Page($response['data']['count'], 10);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show = $page->show();
// 获取配送方式
$shippings = ShippingModel::get();
$ship_type = [];
foreach ($shippings as $k => $v) {
$ship_type[$v->shipping_id] = $v->shipping_name;
}
$info['shippings'] = $ship_type;
$info['condition'] = $map;
$info['list'] = $response['data']['data'];
$info['count'] = $response['data']['count'];
$info['page'] = $show;
// $perm = new PermController;
// $joint_kefu = $perm->getRoleUsers($request, '客服');
// $self_kefu = $perm->getRoleUsers($request, '自营客服');
// $info['sale_list'] = array_merge($joint_kefu, $self_kefu);
$perm = new PermController;
$sale_list = $perm->getUserByDepartmentId(Config('perm_args.sales_department_id')); // 获取所有的销售
$info['sale_list'] = $sale_list;
return $info;
}
// 联营退货单导出
public function returnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->export($request);
}
// 自营退货单导出
public function selfReturnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->export($request);
}
// 退货详情
public function returnDetails(Request $request, $id)
{
$info = $this->getPageInfo($request);
$OrderReturnModel = new OrderReturnModel();
$info['return'] = $OrderReturnModel->find($id);
$info['returnItems'] = $OrderReturnModel->find($id)->hasManyReturnItems;
$info['returnLog'] = $OrderReturnModel->find($id)->hasManyReturnLog;
if ($info['return']['order_goods_type'] == 1) {
$title = '联营订单';
$return_url = '/return_list';
} else {
$title = '自营订单';
$return_url = '/self_return_list';
}
$info['title'] = '订单退货详情';
$info['paths'] = [["title" => $title, "href" => '#'], ["title" => '退货申请列表', "href" => $return_url], ["title" => '订单退货详情', "href" => '#']];
return view('returnDetails', $info);
}
// 退货单审核
public function returnCheck(Request $request)
{
if ($request->isMethod('post')) {
$OrderReturnModel = new OrderReturnModel();
return $OrderReturnModel->check($request);
}
}
// 退货物流信息
public function returnShipping(Request $request)
{
if ($request->isMethod('post')) {
$OrderReturnModel = new OrderReturnModel();
return $OrderReturnModel->shipping($request);
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\UserMainModel;
use App\Model\UserInfoModel;
use App\Model\UserCompanyModel;
use App\Model\OrderModel;
use App\Model\OrderPriceModel;
use App\Model\OrderInvoiceModel;
use App\Model\OrderActionLogModel;
use App\Model\PayLogModel;
use App\Model\UserSampleApplyModel;
use App\Model\UserSampleInviteModel;
use DB;
use Excel;
use Log;
use Exception;
class SpecialController extends Controller
{
// 订单特殊处理,用于测试调整运费
public function changeOrderPrice(Request $request)
{
$mobile = $request->input('mobile', '');
$order_id = $request->input('order_id', '');
if (!$mobile || !$order_id) {
echo '参数缺失';die;
}
// 检查是否为测试账号
$test_mobile = Config('params.test_mobile');
if (!in_array($mobile, $test_mobile)) {
echo '非测试账号';die;
}
DB::connection('order')->beginTransaction();
$order = DB::connection('order')->table('lie_order_price')->where('order_id', $order_id)->where('price_type', 3)->first();
if (!$order) {
echo '运费不存在';die;
}
$data['price'] = 0;
$update = DB::connection('order')->table('lie_order_price')->where('order_id', $order_id)->where('price_type', 3)->update($data);
if (!$update) {
DB::connection('order')->rollback();
echo '运费更新失败';die;
}
$OrderModel = new OrderModel();
$order_info = $OrderModel->find($order_id);
$intracode = DB::table('lie_intracode')->where('user_id', $order_info['user_id'])->select('admin_id')->first();
$sale_id = $intracode ? $intracode->admin_id : 0;
// 操作记录
$OrderActionLogModel = new OrderActionLogModel();
$actionLog = $OrderActionLogModel->addLog($order_id, $sale_id, 2, '调整运费为0');
if (!$actionLog) {
DB::connection('order')->rollback();
echo '添加运费更新日志失败';die;
}
DB::connection('order')->commit();
echo '运费更新成功';
}
// 导出已离职人员数据 (业务ID、业务人、关联会员账号、公司名称)
public function exportDimission()
{
// 查找已离职人员
$dimission = DB::table('user_info')->where('status', 4)->select('userId', 'name')->get();
if (empty($dimission)) {
echo '无离职人员';die;
}
$sales = [];
$sale_ids = [];
foreach ($dimission as $v) {
$sales[$v->userId] = $v->name;
$sale_ids[] = $v->userId;
}
// 查找离职人员订单
$OrderModel = new OrderModel();
$order_info = $OrderModel->from('lie_order as o')
->leftJoin('lie_user_main as u', 'o.user_id', '=', 'u.user_id')
->leftJoin('lie_user_company as c', 'o.user_id', '=', 'c.user_id')
->whereIn('o.sale_id', $sale_ids)
->select('o.order_id', 'o.user_id', 'o.sale_id', 'u.mobile', 'u.email', 'c.com_name')
->get();
if (empty($order_info)) {
echo '无离职人员订单';die;
}
$cellData = [];
foreach ($order_info as $k=>$v) {
$cellData[$k]['sale_id'] = $v['sale_id'];
$cellData[$k]['sale_name'] = $sales[$v['sale_id']];
$cellData[$k]['account'] = $v['mobile'] ? $v['mobile'] : $v['email'];
$cellData[$k]['com_name'] = $v['com_name'];
}
$headerCell = ['业务ID', '业务员名称', '关联会员账号', '公司名称'];
array_unshift($cellData, $headerCell);
$fileName = '已离职人员关联客户'.date('_YmdHis');
Excel::create($fileName, function($excel) use ($cellData){
$excel->sheet('人员导出', function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
}
// 导入离职业务客户
public function importDimission(Request $request)
{
if ($request->isMethod('post')) {
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0); // 读取第二个sheet
$excel = $data->toArray();
});
if (!$excel) {
echo '导入文件为空';die;
}
array_shift($excel); // 删除第一行
$OrderModel = new OrderModel();
// 记录到日志
$monolog = Log::getMonolog();
$monolog->popHandler();
Log::useDailyFiles(storage_path('logs/updateOrder.log'));
foreach ($excel as $k=>$v) {
if (!$v[0] || !$v[1]) continue;
// 1. 根据手机或邮箱查找客户最近的订单
$res = $this->getLastOrderId(trim($v[0]));
if ($res['err_code'] != 0) {
Log::info('客户账号:'.$v[0].','.$res['err_msg']);
continue;
}
$order_id = $res['data'];
// 2. 根据企业邮箱查找sale_id
$sale_id = $this->getSaleId(trim(strtolower($v[1])));
if ($sale_id === false) {
Log::info('客户账号:'.$v[0].',客服邮箱:'.$v[1].',没有找到跟进人邮箱');
continue;
}
// 3. 替换第一步的订单sale_id
$OrderModel->where('order_id', $order_id)->update(['sale_id' => $sale_id]);
Log::info('客户账号:'.$v[0].',客服邮箱:'.$v[1].',替换已离职人员的订单,订单ID:'.$order_id.',之前的SALE ID:'.$sale_id);
}
echo '替换sale_id完成';die;
}
return view('importDimission');
}
// 获取客户最近的订单
public function getLastOrderId($account)
{
$UserMainModel = new UserMainModel();
$UserCompanyModel = new UserCompanyModel();
$OrderModel = new OrderModel();
$OrderInvoiceModel = new OrderInvoiceModel();
if (strpos($account, '@') !== false) { // 邮箱
$where['email'] = strtolower($account);
$user_info = $UserMainModel->where($where)->select('user_id')->orderBy('user_id', 'desc')->first();
} else if (preg_match('/\d{11}/', $account)) { // 手机号码
$where['mobile'] = $account;
$user_info = $UserMainModel->where($where)->select('user_id')->orderBy('user_id', 'desc')->first();
} else { // 公司名称
// 发票抬头
$order_invoice = $OrderInvoiceModel->where('tax_title', $account)->select('order_id')->orderBy('order_id', 'desc')->first();
if ($order_invoice) return ['err_code' => 0, 'err_msg' => '', 'data' => $order_invoice['order_id']];
$user_info = $UserCompanyModel->where('com_name', $account)->select('user_id')->orderBy('com_id', 'desc')->first();
}
if (!$user_info) return ['err_code' => 1, 'err_msg' => '未找到客户'];
// 查找最近的订单
$order = $OrderModel->where('user_id', $user_info['user_id'])->where('is_type', 0)->select('order_id')->orderBy('order_id', 'desc')->first();
if (!$order) return ['err_code' => 2, 'err_msg' => '未找到客户订单'];
return ['err_code' => 0, 'err_msg' => '', 'data' => $order['order_id']];
}
// 获取后台业务ID
public function getSaleId($email)
{
$user = DB::table('user_info')->where('email', $email)->select('userId')->first();
if (!$user) return false;
return $user->userId;
}
// 处理支付记录
public function handlePayLog()
{
// $PayLogModel = new PayLogModel();
// $pay_log = $PayLogModel->where('pay_type', 4)->where('is_paid', -1)->orderBy('create_time', 'desc')->get()->toArray();
// $data = [];
// foreach ($pay_log as $k=>$v) {
// $log = $PayLogModel->where('order_id', $v['order_id'])->where('pay_type', 1)->first();
// if (!$log)
// continue;
// // dump($log['order_id'].'==='.date('Y-m-d H:i:s', $log['create_time']).'==='.date('Y-m-d H:i:s', $log['pay_time']));
// // $PayLogModel->where('pay_log_id', $v['pay_log_id'])->update(['is_paid'=>1, 'pay_time'=>$log['pay_time']]); // 更新账期支付
// // $PayLogModel->where('pay_log_id', $log['pay_log_id'])->delete();
// // // 记录到日志
// // $monolog = Log::getMonolog();
// // $monolog->popHandler();
// // Log::useDailyFiles(storage_path('logs/update_pay_log.log'));
// // Log::info('更新账期支付记录ID:'.$v['pay_log_id'].',删除的支付记录ID:'.$log['pay_log_id']);
// $data[] = $log['pay_log_id'];
// }
// dd($data);
}
// 自营预售订单改预付款
public function changeOrderPayType(Request $request)
{
$order_id = $request->input('order_id', 0);
if (!$order_id) return '订单ID不存在';
DB::connection('order')->transaction(function() use ($order_id) {
$OrderModel = new OrderModel();
$OrderPriceModel = new OrderPriceModel();
$PayLogModel = new PayLogModel();
$OrderActionLogModel = new OrderActionLogModel();
// 查询订单信息
$order_info = $OrderModel->find($order_id);
if (!$order_info) throw new Exception("修改失败,订单不存在", 1);
if ($order_info['status'] > 2) throw new Exception("修改失败,订单已支付", 1);
$advance_amount = number_format($order_info['order_amount'] * 0.3, 2);
// 订单表
$order = array();
$order['order_pay_type'] = 2;
$order['advance_amount'] = $advance_amount;
$order['status'] = 3;
$order['advance_pay_time'] = time();
$OrderModel->where('order_id', $order_id)->update($order);
// 支付记录表
$pay_log = array();
$pay_log['order_id'] = $order_id;
$pay_log['pay_id'] = 0; // 支付方式ID
$pay_log['pay_name'] = '交通银行'; // 支付方式名
$pay_log['pay_type'] = 2;
$pay_log['pay_amount'] = $advance_amount;
$pay_log['is_paid'] = 1;
$pay_log['create_time'] = time();
$pay_log['pay_time'] = time();
$PayLogModel->insert($pay_log);
// 价格表
$price = array();
$price['order_id'] = $order_id;
$price['order_sn'] = '12019101531990';
$price['price_type'] = -2;
$price['price'] = '-'.$advance_amount;
$price['currency'] = $order_info['currency'];
$price['create_time'] = time();
$OrderPriceModel->insert($price);
// 操作日志
$OrderActionLogModel->addLog($order_id, 1000, 2, '手动调整订单支付类型');
});
return '调整成功';
}
// 自营样片设置过期,剩余领取机会归零,不在领取表的用户默认1次领取机会
public function setSampleExpire()
{
$UserInfoModel = new UserInfoModel;
$UserSampleApplyModel = new UserSampleApplyModel;
$UserSampleInviteModel = new UserSampleInviteModel;
$res = $UserSampleApplyModel->where('is_expire', 1)->update(['is_expire' => -1]);
dump($res);
$res = $UserSampleInviteModel->where('is_expire', 1)->update(['is_expire' => -1]);
dump($res);
$user_ids = $UserSampleApplyModel->where('is_expire', -1)->groupBy('user_id')->lists('user_id')->toArray();
if ($user_ids) {
$res = $UserInfoModel->whereIn('user_id', $user_ids)->update(['apply_count' => 0]);
dump($res);
$res = $UserInfoModel->whereNotIn('user_id', $user_ids)->where('apply_count', '>', 1)->update(['apply_count' => 1]);
dump($res);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\UserMainModel;
use App\Model\UserInfoModel;
use App\Model\UserCompanyModel;
use App\Model\OrderModel;
use App\Model\OrderPriceModel;
use App\Model\OrderInvoiceModel;
use App\Model\OrderActionLogModel;
use App\Model\PayLogModel;
use App\Model\UserSampleApplyModel;
use App\Model\UserSampleInviteModel;
use DB;
use Excel;
use Log;
use Exception;
class SpecialController extends Controller
{
// 订单特殊处理,用于测试调整运费
public function changeOrderPrice(Request $request)
{
$mobile = $request->input('mobile', '');
$order_id = $request->input('order_id', '');
if (!$mobile || !$order_id) {
echo '参数缺失';die;
}
// 检查是否为测试账号
$test_mobile = Config('params.test_mobile');
if (!in_array($mobile, $test_mobile)) {
echo '非测试账号';die;
}
DB::connection('order')->beginTransaction();
$order = OrderPriceModel::where('order_id', $order_id)->where('price_type', 3)->first();
if (!$order) {
echo '运费不存在';die;
}
$data['price'] = 0;
$update = OrderPriceModel::where('order_id', $order_id)->where('price_type', 3)->update($data);
if (!$update) {
DB::connection('order')->rollback();
echo '运费更新失败';die;
}
$OrderModel = new OrderModel();
$order_info = $OrderModel->find($order_id);
$intracode = DB::table('lie_intracode')->where('user_id', $order_info['user_id'])->select('admin_id')->first();
$sale_id = $intracode ? $intracode->admin_id : 0;
// 操作记录
$OrderActionLogModel = new OrderActionLogModel();
$actionLog = $OrderActionLogModel->addLog($order_id, $sale_id, 2, '调整运费为0');
if (!$actionLog) {
DB::connection('order')->rollback();
echo '添加运费更新日志失败';die;
}
DB::connection('order')->commit();
echo '运费更新成功';
}
// 导出已离职人员数据 (业务ID、业务人、关联会员账号、公司名称)
public function exportDimission()
{
// 查找已离职人员
$dimission = DB::table('user_info')->where('status', 4)->select('userId', 'name')->get();
if (empty($dimission)) {
echo '无离职人员';die;
}
$sales = [];
$sale_ids = [];
foreach ($dimission as $v) {
$sales[$v->userId] = $v->name;
$sale_ids[] = $v->userId;
}
// 查找离职人员订单
$OrderModel = new OrderModel();
$order_info = $OrderModel->from('lie_order as o')
->leftJoin('lie_user_main as u', 'o.user_id', '=', 'u.user_id')
->leftJoin('lie_user_company as c', 'o.user_id', '=', 'c.user_id')
->whereIn('o.sale_id', $sale_ids)
->select('o.order_id', 'o.user_id', 'o.sale_id', 'u.mobile', 'u.email', 'c.com_name')
->get();
if (empty($order_info)) {
echo '无离职人员订单';die;
}
$cellData = [];
foreach ($order_info as $k=>$v) {
$cellData[$k]['sale_id'] = $v['sale_id'];
$cellData[$k]['sale_name'] = $sales[$v['sale_id']];
$cellData[$k]['account'] = $v['mobile'] ? $v['mobile'] : $v['email'];
$cellData[$k]['com_name'] = $v['com_name'];
}
$headerCell = ['业务ID', '业务员名称', '关联会员账号', '公司名称'];
array_unshift($cellData, $headerCell);
$fileName = '已离职人员关联客户'.date('_YmdHis');
Excel::create($fileName, function($excel) use ($cellData){
$excel->sheet('人员导出', function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
}
// 导入离职业务客户
public function importDimission(Request $request)
{
if ($request->isMethod('post')) {
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0); // 读取第二个sheet
$excel = $data->toArray();
});
if (!$excel) {
echo '导入文件为空';die;
}
array_shift($excel); // 删除第一行
$OrderModel = new OrderModel();
// 记录到日志
$monolog = Log::getMonolog();
$monolog->popHandler();
Log::useDailyFiles(storage_path('logs/updateOrder.log'));
foreach ($excel as $k=>$v) {
if (!$v[0] || !$v[1]) continue;
// 1. 根据手机或邮箱查找客户最近的订单
$res = $this->getLastOrderId(trim($v[0]));
if ($res['err_code'] != 0) {
Log::info('客户账号:'.$v[0].','.$res['err_msg']);
continue;
}
$order_id = $res['data'];
// 2. 根据企业邮箱查找sale_id
$sale_id = $this->getSaleId(trim(strtolower($v[1])));
if ($sale_id === false) {
Log::info('客户账号:'.$v[0].',客服邮箱:'.$v[1].',没有找到跟进人邮箱');
continue;
}
// 3. 替换第一步的订单sale_id
$OrderModel->where('order_id', $order_id)->update(['sale_id' => $sale_id]);
Log::info('客户账号:'.$v[0].',客服邮箱:'.$v[1].',替换已离职人员的订单,订单ID:'.$order_id.',之前的SALE ID:'.$sale_id);
}
echo '替换sale_id完成';die;
}
return view('importDimission');
}
// 获取客户最近的订单
public function getLastOrderId($account)
{
$UserMainModel = new UserMainModel();
$UserCompanyModel = new UserCompanyModel();
$OrderModel = new OrderModel();
$OrderInvoiceModel = new OrderInvoiceModel();
if (strpos($account, '@') !== false) { // 邮箱
$where['email'] = strtolower($account);
$user_info = $UserMainModel->where($where)->select('user_id')->orderBy('user_id', 'desc')->first();
} else if (preg_match('/\d{11}/', $account)) { // 手机号码
$where['mobile'] = $account;
$user_info = $UserMainModel->where($where)->select('user_id')->orderBy('user_id', 'desc')->first();
} else { // 公司名称
// 发票抬头
$order_invoice = $OrderInvoiceModel->where('tax_title', $account)->select('order_id')->orderBy('order_id', 'desc')->first();
if ($order_invoice) return ['err_code' => 0, 'err_msg' => '', 'data' => $order_invoice['order_id']];
$user_info = $UserCompanyModel->where('com_name', $account)->select('user_id')->orderBy('com_id', 'desc')->first();
}
if (!$user_info) return ['err_code' => 1, 'err_msg' => '未找到客户'];
// 查找最近的订单
$order = $OrderModel->where('user_id', $user_info['user_id'])->where('is_type', 0)->select('order_id')->orderBy('order_id', 'desc')->first();
if (!$order) return ['err_code' => 2, 'err_msg' => '未找到客户订单'];
return ['err_code' => 0, 'err_msg' => '', 'data' => $order['order_id']];
}
// 获取后台业务ID
public function getSaleId($email)
{
$user = DB::table('user_info')->where('email', $email)->select('userId')->first();
if (!$user) return false;
return $user->userId;
}
// 处理支付记录
public function handlePayLog()
{
// $PayLogModel = new PayLogModel();
// $pay_log = $PayLogModel->where('pay_type', 4)->where('is_paid', -1)->orderBy('create_time', 'desc')->get()->toArray();
// $data = [];
// foreach ($pay_log as $k=>$v) {
// $log = $PayLogModel->where('order_id', $v['order_id'])->where('pay_type', 1)->first();
// if (!$log)
// continue;
// // dump($log['order_id'].'==='.date('Y-m-d H:i:s', $log['create_time']).'==='.date('Y-m-d H:i:s', $log['pay_time']));
// // $PayLogModel->where('pay_log_id', $v['pay_log_id'])->update(['is_paid'=>1, 'pay_time'=>$log['pay_time']]); // 更新账期支付
// // $PayLogModel->where('pay_log_id', $log['pay_log_id'])->delete();
// // // 记录到日志
// // $monolog = Log::getMonolog();
// // $monolog->popHandler();
// // Log::useDailyFiles(storage_path('logs/update_pay_log.log'));
// // Log::info('更新账期支付记录ID:'.$v['pay_log_id'].',删除的支付记录ID:'.$log['pay_log_id']);
// $data[] = $log['pay_log_id'];
// }
// dd($data);
}
// 自营预售订单改预付款
public function changeOrderPayType(Request $request)
{
$order_id = $request->input('order_id', 0);
if (!$order_id) return '订单ID不存在';
DB::connection('order')->transaction(function() use ($order_id) {
$OrderModel = new OrderModel();
$OrderPriceModel = new OrderPriceModel();
$PayLogModel = new PayLogModel();
$OrderActionLogModel = new OrderActionLogModel();
// 查询订单信息
$order_info = $OrderModel->find($order_id);
if (!$order_info) throw new Exception("修改失败,订单不存在", 1);
if ($order_info['status'] > 2) throw new Exception("修改失败,订单已支付", 1);
$advance_amount = number_format($order_info['order_amount'] * 0.3, 2);
// 订单表
$order = array();
$order['order_pay_type'] = 2;
$order['advance_amount'] = $advance_amount;
$order['status'] = 3;
$order['advance_pay_time'] = time();
$OrderModel->where('order_id', $order_id)->update($order);
// 支付记录表
$pay_log = array();
$pay_log['order_id'] = $order_id;
$pay_log['pay_id'] = 0; // 支付方式ID
$pay_log['pay_name'] = '交通银行'; // 支付方式名
$pay_log['pay_type'] = 2;
$pay_log['pay_amount'] = $advance_amount;
$pay_log['is_paid'] = 1;
$pay_log['create_time'] = time();
$pay_log['pay_time'] = time();
$PayLogModel->insert($pay_log);
// 价格表
$price = array();
$price['order_id'] = $order_id;
$price['order_sn'] = '12019101531990';
$price['price_type'] = -2;
$price['price'] = '-'.$advance_amount;
$price['currency'] = $order_info['currency'];
$price['create_time'] = time();
$OrderPriceModel->insert($price);
// 操作日志
$OrderActionLogModel->addLog($order_id, 1000, 2, '手动调整订单支付类型');
});
return '调整成功';
}
// 自营样片设置过期,剩余领取机会归零,不在领取表的用户默认1次领取机会
public function setSampleExpire()
{
$UserInfoModel = new UserInfoModel;
$UserSampleApplyModel = new UserSampleApplyModel;
$UserSampleInviteModel = new UserSampleInviteModel;
$res = $UserSampleApplyModel->where('is_expire', 1)->update(['is_expire' => -1]);
dump($res);
$res = $UserSampleInviteModel->where('is_expire', 1)->update(['is_expire' => -1]);
dump($res);
$user_ids = $UserSampleApplyModel->where('is_expire', -1)->groupBy('user_id')->lists('user_id')->toArray();
if ($user_ids) {
$res = $UserInfoModel->whereIn('user_id', $user_ids)->update(['apply_count' => 0]);
dump($res);
$res = $UserInfoModel->whereNotIn('user_id', $user_ids)->where('apply_count', '>', 1)->update(['apply_count' => 1]);
dump($res);
}
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Page;
use App\Map\PcbOrderInvoiceMap;
use App\Map\PcbOrderMap;
......@@ -15,12 +17,9 @@ use App\Model\PaymentDaysModel;
use App\Model\Pcb\PcbOrderModel;
use App\Model\Pcb\PcbPublicModel;
use App\Model\Pcb\PcbPurchaseModel;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\PermController;
use DB;
use App\Model\UserMainModel;
use App\Model\UserInfoModel;
use App\Model\UserCompanyModel;
......@@ -31,6 +30,8 @@ use App\Model\OrderServiceLogModel;
use App\Model\OrderExtendModel;
use App\Model\PayLogModel;
use App\Model\OrderInvoiceModel;
use App\Model\ShippingModel;
use DB;
class WebController extends Controller
{
......@@ -97,7 +98,7 @@ class WebController extends Controller
$data['title']='PCB交易列表';
$data['order_type'] = PcbOrderMap::$order_type;
$data['status'] = PcbOrderMap::$status;
$data['shipping'] = objectToArray(DB::connection("order")->table("lie_shipping")->get());
$data['shipping'] = objectToArray(ShippingModel::get());
//分页
$response = (new PcbOrderModel())->getList();
$page = new Page($response[3], 10);
......@@ -164,7 +165,7 @@ class WebController extends Controller
$orderBase['create_time'] = $orderBase['create_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['create_time']) : "";
$orderBase['finish_time'] = $orderBase['finish_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['finish_time']) : "";
$orderBase['pay_time'] = $orderBase['pay_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['pay_time']) : "";
$userCompany = DB::connection('order')->table("lie_user_company")->where("user_id",$orderBase['user_id'])->first();
$userCompany = UserCompanyModel::where("user_id",$orderBase['user_id'])->first();
$orderBase['company_name'] = $userCompany ? $userCompany->com_name : "" ;
//拼接收货信息
$RegionController = new RegionController();
......@@ -250,7 +251,7 @@ class WebController extends Controller
$orderBase['create_time'] = $orderBase['create_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['create_time']) : "";
$orderBase['finish_time'] = $orderBase['finish_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['finish_time']) : "";
$orderBase['pay_time'] = $orderBase['pay_time'] > 0 ? date('Y-m-d H:i:s',$orderBase['pay_time']) : "";
$userCompany = DB::connection('order')->table("lie_user_company")->where("user_id",$orderBase['user_id'])->first();
$userCompany = UserCompanyModel::where("user_id",$orderBase['user_id'])->first();
$orderBase['company_name'] = $userCompany ? $userCompany->com_name : "" ;
//拼接采购信息
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class InvoiceCompanyModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_invoice_company';
protected $primaryKey = 'id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class OrderReturnItemsModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_return_items';
protected $primaryKey = 'return_items_id';
public $timestamps = false;
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class OrderReturnItemsModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_return_items';
protected $primaryKey = 'return_items_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class RemovalItemsModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_removal_items';
protected $primaryKey = 'removal_items_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class ShippingModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_shipping';
protected $primaryKey = 'shipping_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
class ShoppingCartModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_shopping_cart';
protected $primaryKey = 'cart_id';
public $timestamps = false;
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
class ShoppingCartModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_shopping_cart';
protected $primaryKey = 'cart_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class TaxInfoModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_taxinfo';
protected $primaryKey = 'tax_id';
public $timestamps = false;
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserAddressModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_user_address';
protected $primaryKey = 'address_id';
public $timestamps = false;
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ use App\Model\RegionModel;
class UserCompanyModel extends Model
{
protected $connection = 'order';
protected $connection = 'web';
protected $table = 'lie_user_company';
protected $primaryKey = 'com_id';
public $timestamps = false;
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserMainModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_user_main';
protected $primaryKey = 'user_id';
public $timestamps = false;
// 测试帐号
public function testMobile()
{
$testId = array();
$user = $this->where(['is_test' => 1])->select('user_id')->get()->toArray();
foreach ($user as $k => $v) {
$testId[$k] = $v['user_id'];
}
return $testId;
}
// 获取用户账号
public function getUserAccount($user_id)
{
return $this->where('user_id', $user_id)->select('user_id', 'mobile', 'email')->first();
}
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserMainModel extends Model
{
protected $connection = 'web';
protected $table = 'lie_user_main';
protected $primaryKey = 'user_id';
public $timestamps = false;
// 测试帐号
public function testMobile()
{
$testId = array();
$user = $this->where(['is_test' => 1])->select('user_id')->get()->toArray();
foreach ($user as $k => $v) {
$testId[$k] = $v['user_id'];
}
return $testId;
}
// 获取用户账号
public function getUserAccount($user_id)
{
return $this->where('user_id', $user_id)->select('user_id', 'mobile', 'email')->first();
}
}
\ No newline at end of file
......@@ -71,16 +71,29 @@ return [
'strict' => false,
],
'order' => [
'web' => [
'driver' => 'mysql',
'host' => env('DB_HOST', ''),
'database' => env('DB_DATABASE_WEB', ''),
'username' => env('DB_USERNAME_WEB', ''),
'password' => env('DB_PASSWORD_WEB', ''),
'port' => env('DB_PORT', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'order' => [
'driver' => 'mysql',
'host' => env('DB_HOST_ORDER', ''),
'database' => env('DB_DATABASE_ORDER', ''),
'username' => env('DB_USERNAME_ORDER', ''),
'password' => env('DB_PASSWORD_ORDER', ''),
'port' => env('DB_PORT', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'prefix' => env('DB_PREFIX_ORDER', ''),
'strict' => false,
],
......
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