Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

朱继来 / 后台订单管理

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • Order
  • app
  • Http
  • Controllers
  • AddOrderController.php
AddOrderController.php 29.7 KB
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
1 2 3 4 5 6 7 8 9 10 11
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Cookie;
use App\Http\Page;
use App\Http\Controllers\PermController;
朱继来's avatar
调整新增自营线下订单
89258934
 
朱继来 committed 6 years ago
12
use App\Http\Error;
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
13 14
use App\Model\UserMainModel;
use App\Model\OrderModel;
朱继来's avatar
temp
2c3fcf9a
 
朱继来 committed 6 years ago
15
use Excel;
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

Class AddOrderController extends Controller
{
	// 页面用户、菜单信息
    public function getPageInfo(Request $request)
    {
        $uri = '/' . $request->path();

        $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;

朱继来's avatar
调整权限菜单
092d0dbb
 
朱继来 committed 6 years ago
35 36 37
        // 用户角色
        $role = $perm->getUserRole($request);

朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
38
        // 获取权限菜单
朱继来's avatar
调整权限菜单
092d0dbb
 
朱继来 committed 6 years ago
39 40 41
        if ($role != 1) {
            $menus = $perm->getPermMenu($menus, $request->user->userId);   
        }
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
42 43 44 45 46 47 48

        $data = [
            'header'    => $request->user->header,
            'uri'       => $uri,
            'username'  => $username,
            'useremail' => $useremail,
            'menus'     => $menus,
朱继来's avatar
自营已分配订单,客服主管或助理可以下单
fc53bbe3
 
朱继来 committed 5 years ago
49
            'role'      => $role,
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
50 51 52 53 54
        ];

        return $data;
    }

朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    // 新增联营订单
    public function addOrder(Request $request)
    {
        $info = $this->getPageInfo($request);

        $info['title'] = '新增联营订单';
        $info['sale_id'] = $request->user->userId;

        return view('addOrder', $info);
    }

    // 新增自营线上订单
    public function addOnline(Request $request)
    {
        $info = $this->getPageInfo($request);

        $info['title'] = '新增自营线上订单';
        $info['sale_id'] = $request->user->userId;

        return view('addOnline', $info);
    }

朱继来's avatar
1. 添加支付优惠;
29fe9a35
 
朱继来 committed 6 years ago
77 78 79 80 81 82 83 84 85 86 87
    // 新增自营其他业务订单
    public function addOtherOrder(Request $request)
    {
        $info = $this->getPageInfo($request);

        $info['title'] = '新增自营其他业务订单';
        $info['sale_id'] = $request->user->userId;

        return view('addOtherOrder', $info);
    }

朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
88 89 90 91
    // 获取用户信息
    public function getUserInfo(Request $request)
    {
        if ($request->isMethod('post')) {
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
92
            $mobile      = $request->input('mobile');
allen's avatar
crm转移到订单系统
93f7880f
 
allen committed 5 years ago
93
            $user_id      = $request->input('user_id');
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
94 95 96 97
            $goods_type  = $request->input('goods_type'); // 类型,1-联营,2-自营
            $operator_id = $request->user->userId;

            $UserMainModel = new UserMainModel;
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
98

allen's avatar
调整权限 重新重新开放
d8d02b6a
 
allen committed 5 years ago
99
            if(!empty($user_id) && strlen($request->input('user_id')<11 ) ){
allen's avatar
crm转移到订单系统
93f7880f
 
allen committed 5 years ago
100
                
allen's avatar
修改数据取出
4ebb5841
 
allen committed 5 years ago
101
                 $user = $UserMainModel->where('user_id', $user_id)->select('user_id', 'email','mobile', 'is_test')->orderBy('create_time', 'desc')->first();
allen's avatar
crm转移到订单系统
93f7880f
 
allen committed 5 years ago
102 103 104 105 106 107 108 109 110
            }else{
                if (preg_match('/@/', $mobile)) {
                    $user = $UserMainModel->where('email', $mobile)->select('user_id', 'email', 'is_test')->orderBy('create_time', 'desc')->first();
                } else {
                    $user = $UserMainModel->where('mobile', $mobile)->select('user_id', 'mobile', 'is_test')->orderBy('create_time', 'desc')->first();
                }
            }


朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
111 112 113 114

            if (!empty($user)) {    
                $perm = new PermController;   
                $role = $perm->getUserRole($request); // 用户角色
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
115

朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
116 117
                if ($goods_type == 1 || ($goods_type == 2 && !in_array($role, [1, 10, 11]))) { // 自营管理员、主管、主管助理可以帮客服下单
                    $last_sale_id = $this->findLastSaleId($user->user_id);
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
118

朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
119 120 121 122 123
                    if ($last_sale_id && $operator_id != $last_sale_id) return ['errcode' => -1, 'errmsg' => '暂不能跟进该客户,请联系主管重新指派'];
                }

                $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(); // 发票信息
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
124
                
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
125
                $info['user']    = $user;
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
126 127 128 129 130 131 132 133 134 135 136 137
                $info['address'] = $address;
                $info['invoice'] = $invoice;
            }           

            if (isset($info)) {
                return ['errcode' => 0, 'errmsg' => '', 'data' => $info];
            } else {
                return ['errcode' => -1, 'errmsg' => '未找用户信息'];
            }
        }
    }

朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
138 139 140 141 142 143 144 145 146
    // 获取用户最近的订单跟进业务员
    public function findLastSaleId($user_id)
    {
        $OrderModel = new OrderModel;

        $map['user_id'] = $user_id;
        $map['is_type'] = 0; // 过滤尽调数据
        $map[] = ['sale_id', '>', 0];

朱继来's avatar
调整获取用户信息
bf2563fb
 
朱继来 committed 5 years ago
147
        $order = $OrderModel->where($map)->select('sale_id')->orderBy('order_id', 'desc')->first();
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
148 149 150 151

        return $order ? $order['sale_id'] : 0;
    }

朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    // 选择收货地址
    public function selectAddr(Request $request)
    {
        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->province_val = $this->getAddress($address->province);
            $address->city_val = $this->getAddress($address->city);
            $address->district_val = $this->getAddress($address->district);

            return ['errcode' => 0, 'errmsg' => '', 'data' => $address];
        }
    }

    // 选择发票信息
    public function selectInv(Request $request)
    {
        if ($request->isMethod('post')) {
            $tax_id = $request->input('tax_id');

            $invoice = DB::connection('order')->table('lie_taxinfo')->where('tax_id', $tax_id)->first();

朱继来's avatar
调整发票信息
4fe40439
 
朱继来 committed 6 years ago
176 177 178
            $invoice->province_val = $invoice->consignee_province ? $this->getAddress($invoice->consignee_province) : '';
            $invoice->city_val = $invoice->consignee_city ? $this->getAddress($invoice->consignee_city) : '';
            $invoice->district_val = $invoice->consignee_district ? $this->getAddress($invoice->consignee_district) : '';
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

            return ['errcode' => 0, 'errmsg' => '', 'data' => $invoice];
        }
    }

    // 根据发票类型选择发票信息
    public function selectInvType(Request $request)
    {
        if ($request->isMethod('post')) {
            $user_id = $request->input('user_id');
            $inv_type = $request->input('inv_type');

            if ($inv_type == 3) {
                $invoice = DB::connection('order')->table('lie_taxinfo')->where(['user_id' => $user_id, 'inv_type' => $inv_type])->get();
            } else {
                $invoice = DB::connection('order')->table('lie_taxinfo')->where('user_id', $user_id)->whereIn('inv_type', [2, 4])->get();
            }
            
            return ['errcode' => 0, 'errmsg' => '', 'data' => $invoice];
        }
    }

    // 获取可用优惠券
    public function getCoupon(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['uid'] = $request->input('uid');
            $data['order_goods_type'] = $request->input('goods_type');
            $data['cart_ids'] = $request->input('cart_ids');        

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'ucoupon/bestusebyordersystem';

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
214
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
215 216 217 218 219 220 221 222 223

            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }
        }
    }

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
224 225 226 227 228
    // 查询省市区
    public function getAddress($id)
    {
        $addr = DB::connection('order')->table('lie_region')->where('region_id', $id)->select('region_name')->first();

朱继来's avatar
调整查询省市区
2c0af0fd
 
朱继来 committed 6 years ago
229
        return $addr ? $addr->region_name : '未匹配到ID:'.$id;
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
230 231
    }

朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
232 233 234 235 236 237 238 239 240 241 242
	// 新增自营线下订单
    public function addOffline(Request $request) 
    {
        $info = $this->getPageInfo($request);

        $info['title'] = '新增自营线下订单';

        // 默认内部账号ID
        $internal = DB::connection('order')->table('lie_user_main')->where('mobile', Config('website.internal-account'))->select('user_id')->first();
        $info['internal_uid'] = $internal->user_id;

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
243 244 245 246
        // 默认内部账号收货地址
        $address = DB::connection('order')->table('lie_user_address')->where(['user_id' => $info['internal_uid'], 'is_default' => 1])->first();
        
        $address->province_val = $this->getAddress($address->province);
朱继来's avatar
调整内部采购下单
4cd5e5d4
 
朱继来 committed 6 years ago
247 248 249
        $address->city_val     = $this->getAddress($address->city);
        $address->district_val = $this->getAddress($address->district); 
             
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
250
        $info['address'] = $address;
朱继来's avatar
添加sale_id
ddfbe6c3
 
朱继来 committed 6 years ago
251
        $sale_id         = $request->user->userId;
朱继来's avatar
调整内部采购下单
4cd5e5d4
 
朱继来 committed 6 years ago
252
        $info['sale_id'] = $request->user->userId;
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
253 254 255 256 257 258 259 260 261 262 263

        // 当前登录用户名称
        $userInfo = DB::table('user_info')->where('userId', $sale_id)->select('name')->first(); 
        $info['name'] = $userInfo->name;

        // 当前登录用户内部绑定手机
        $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();

朱继来's avatar
调整内部采购下单手机号码显示
c594eb74
 
朱继来 committed 6 years ago
264
            $info['mobile'] = $user ? $user->mobile : '';
朱继来's avatar
调整内部采购下单
4cd5e5d4
 
朱继来 committed 6 years ago
265 266
        } else {
            $info['mobile'] = '';
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
267 268 269 270 271 272 273 274 275 276
        }

        return view('addOffline', $info);
    }  

    // 获取SKU信息
    public function getSku(Request $request)
    {
        if ($request->isMethod('post')) {
            $url = Config('website.search-skuid');
朱继来's avatar
调整sku接口
698e493b
 
朱继来 committed 6 years ago
277 278 279 280 281
            $data['id'] = $request->input('sku_id');

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
282
            $response = json_decode(curlApi($url, $data, 'POST'), true); 
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
283

朱继来's avatar
调整sku接口
698e493b
 
朱继来 committed 6 years ago
284 285
            if (!empty($response['data'])) {
                return ['errcode' => 0, 'errmsg' => '', 'data' => $response['data']];
朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
286 287 288 289 290 291
            } else {
                return ['errcode' => -1, 'errmsg' => '未找SKU信息'];
            }
        }
    }

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
292 293 294 295 296 297 298 299 300
    // 添加到购物车
    public function addCart(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['uid'] = $request->input('uid');
            $data['id'] = $request->input('id');
            $data['num'] = $request->input('num');
            $data['buy'] = $request->input('buy');
            $data['delivery_place'] = $request->input('delivery_place');
朱继来's avatar
调整后台添加商品
28fa30cf
 
朱继来 committed 6 years ago
301
            $data['type'] = 2; // 后台添加标记
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
302 303 304 305 306 307 308
            $data['pf'] = 4;

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'cart/addByOrderSystem';

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
309
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
调整加入购物车返回数据
bcee6243
 
朱继来 committed 6 years ago
310 311 312 313 314 315
        
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
316 317 318
        }
    }

朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
319 320 321 322 323 324 325 326 327 328 329 330
    // 切换销售类型
    public function switchSaleType(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['sale_type'] = $request->input('sale_type');
            $data['cart_ids'] = $request->input('cart_ids');

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'cart/switchSaleType';

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
331
            $response = json_decode(curlApi($url, $data), true);  
朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
332 333 334 335 336

            return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
        }
    }

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
337 338 339 340 341 342
    // 获取购物车列表
    public function cartList(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['uid'] = $request->input('uid');
            $data['type'] = $request->input('type');
朱继来's avatar
调整新增订单
0831899d
 
朱继来 committed 6 years ago
343
            $data['delivery_place'] = $request->input('delivery_place');
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
344 345 346 347 348 349

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'cart/listsByOrderSystem';

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
350
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
         
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }
        }
    }

    // 修改购物车商品数量
    public function changeNum(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['uid'] = $request->input('uid');
            $data['num'] = $request->input('num');
            $data['cart_id'] = $request->input('cart_id');
朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
367 368
            $type = $request->input('type'); // 3-批量添加的商品
            $goods_type = $request->input('goods_type');
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
369 370 371 372

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
373 374 375 376 377
            if ($type == 3 && $goods_type == 1) { // 联营批量添加
                $url = Config('website.api_domain').'cart/changeNumForJoint';
            } else {
                $url = Config('website.api_domain').'cart/changeNumByOrderSystem';
            }    
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
378

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
379
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
            
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }            
        }
    }

    // 删除购物车商品
    public function deleteGoods(Request $request)
    {
        if ($request->isMethod('post')) {        
            $data['uid'] = $request->input('uid');
            $data['cart_id'] = $request->input('cart_id');

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'cart/deleteByOrderSystem';

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
401
            $response = json_decode(curlApi($url, $data), true);  
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
402 403 404 405 406 407 408 409 410
            
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }            
        }
    }

朱继来's avatar
1. 调整后台下单接口、订单备注;
54bf524d
 
朱继来 committed 6 years ago
411 412
    // 确认订单信息
    public function confirm(Request $request) 
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
413
    {
朱继来's avatar
内部采购下单
82ea1b07
 
朱继来 committed 6 years ago
414
        if ($request->isMethod('post')) {  
朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
415
            $is_online = $request->input('is_online');
朱继来's avatar
1. 调整后台下单接口、订单备注;
54bf524d
 
朱继来 committed 6 years ago
416 417 418 419
            $data['uid'] = $request->input('uid', 0);
            $data['address_id'] = $request->input('address_id', 0);
            $data['cart_id'] = $request->input('cart_ids', '');
            $data['user_coupon_id'] = $request->input('user_coupon_id', 0);
朱继来's avatar
调整内部下单
2301f6f6
 
朱继来 committed 6 years ago
420 421 422 423 424 425 426 427 428
            if ($is_online == 0) {
                $data['type'] = 3; // 自营线下
            } else if ($is_online == 2) {
                $data['type'] = 4; // 自营其他业务
                $data['business_type'] = $request->input('business_type', 0); // 业务类型
            } else {
                $data['type'] = $request->input('goods_type');
            }
            
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
429 430 431
            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

朱继来's avatar
1. 调整后台下单接口、订单备注;
54bf524d
 
朱继来 committed 6 years ago
432
            $url = Config('website.api_domain').'cart/confirm';
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
433

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
434
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
调整内部下单
2301f6f6
 
朱继来 committed 6 years ago
435
          
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
436 437 438 439 440 441 442 443
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>$response['data']];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }            
        }
    }

朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    // 检查期货库存
    public function checkStock(Request $request)
    {
        if ($request->isMethod('post')) {  
            $cart_info = json_decode($request->input('cart_info', ''), true);
            $sale_type = $request->input('sale_type', 1);

            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

            $url = Config('website.api_domain').'goods/detail';

            $warning_arr = array();

            foreach ($cart_info as $k=>$v) {
                $data['id'] = $v['gid'];

朱继来's avatar
调整后台下单curl请求
5dfbc27c
 
朱继来 committed 6 years ago
461 462 463 464 465
                $res = curlApi($url, $data);

                if (!$res) return ['errcode'=>1, 'errmsg'=>'未访问到API接口,请重新尝试'];

                $response = json_decode($res, true); 
朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493

                if ($sale_type == 1) {
                    // 现货订单--判断下单数量是否大于库存,若大于则弹出提示信息
                    if ($v['num'] > $response['data']['goods_number']) {
                        $temp['goods_name'] = $response['data']['goods_name']; // 型号
                        $temp['stock'] = $response['data']['goods_number']; // 可用库存
                        $warning_arr[] = $temp;
                        $errmsg = '库存不足,建议设置为期货类型';
                    } 
                } else {
                    // 期货订单--判断下单数量是否小于库存,若小于则弹出提示信息
                    if ($v['num'] < $response['data']['goods_number']) {
                        $temp['goods_name'] = $response['data']['goods_name']; // 型号
                        $temp['stock'] = $response['data']['goods_number']; // 可用库存
                        $warning_arr[] = $temp;
                        $errmsg = '您提交的数量有实际库存,建议直接购买现货';
                    } 
                }
            }

            if (!empty($warning_arr)) {
                return ['errcode' => -1, 'errmsg' => $errmsg, 'data'=>json_encode($warning_arr)];
            }
            
            return ['errcode' => 0, 'errmsg' => ''];           
        }
    }

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
494 495 496 497
    // 提交订单
    public function create(Request $request)
    {
        if ($request->isMethod('post')) {        
朱继来's avatar
自营已分配订单,客服主管或助理可以下单
fc53bbe3
 
朱继来 committed 5 years ago
498 499
            $data['uid']        = $request->input('uid');
            $data['sale_id']    = $request->input('sale_id');
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
500
            $data['address_id'] = $request->input('address_id');
朱继来's avatar
自营已分配订单,客服主管或助理可以下单
fc53bbe3
 
朱继来 committed 5 years ago
501 502 503
            $data['cart_id']    = implode(',', $request->input('cart_ids'));
            $data['type']       = $request->input('type');
            $data['remark']     = $request->input('remark');
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
504

朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
505
            if ($data['type'] == 3) { // 自营线下订单
朱继来's avatar
自营已分配订单,客服主管或助理可以下单
fc53bbe3
 
朱继来 committed 5 years ago
506
                $data['address_name']   = $request->input('address_name');
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
507
                $data['address_mobile'] = $request->input('address_mobile');
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
508
            } else { // 联营、自营线上订单
朱继来's avatar
自营已分配订单,客服主管或助理可以下单
fc53bbe3
 
朱继来 committed 5 years ago
509 510
                $data['role']           = $request->input('role', '');
                $data['tax_id']         = $request->input('tax_id');
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
511
                $data['user_coupon_id'] = $request->input('user_coupon_id');
朱继来's avatar
1. 添加支付优惠;
29fe9a35
 
朱继来 committed 6 years ago
512 513 514 515

                if ($data['type'] == 4) {
                    $data['business_type'] = $request->input('business_type');
                }
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
516 517
            }

朱继来's avatar
fix
0e9773fb
 
朱继来 committed 6 years ago
518 519
            $data['sale_type'] = $request->input('sale_type', ''); // 自营线上选择销售类型

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
520 521 522
            $data['k1'] = time();
            $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

朱继来's avatar
1. 调整后台下单接口、订单备注;
54bf524d
 
朱继来 committed 6 years ago
523
            $url = Config('website.api_domain').'order/create';
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
524

朱继来's avatar
调整curl返回
1a52bebe
 
朱继来 committed 6 years ago
525
            $response = json_decode(curlApi($url, $data), true); 
朱继来's avatar
调整后台下单curl请求
5dfbc27c
 
朱继来 committed 6 years ago
526
           
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
            if ($response['err_code'] == 0) {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg'], 'data'=>['order_id' => $response['data'], 'type' => $data['type']]];
            } else {
                return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
            }            
        }
    }

    // 提交订单成功页面
    public function success(Request $request)
    {
        $info = $this->getPageInfo($request);

        $order_id = $request->input('order_id');
        $type = $request->input('type');

朱继来's avatar
1. 添加支付优惠;
29fe9a35
 
朱继来 committed 6 years ago
543 544 545 546 547
        switch ($type) {
            case 1: $title = '新增联营订单'; break;
            case 2: $title = '新增自营线上订单'; break;
            case 3: $title = '新增自营线下订单'; break;
            case 4: $title = '新增自营其他业务订单'; break;
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
548 549 550 551
        }

        $info['title'] = $title;
        $info['paths'] = [["title" => $title, "href" => '#']];
朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
552
        $info['type'] = $type;
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
553 554 555

        $order = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->first();

朱继来's avatar
新增联营、自营线上订单
7d62d6ad
 
朱继来 committed 6 years ago
556 557 558 559 560 561
        if ($type != 3) {
            $user = DB::connection('order')->table('lie_user_main')->where('user_id', $order->user_id)->select('mobile')->first();
            $info['user_info'] = $user;
        }

        $info['order_info'] = $order;  
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
562 563 564 565 566 567 568 569 570

        return view('success', $info);
    }

    // 自营线下订单审核
    public function selfCheck(Request $request)
    {
        if ($request->isMethod('post')) {        
            $order_id = $request->input('order_id');
朱继来's avatar
调整新增自营线下订单
89258934
 
朱继来 committed 6 years ago
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
            $status = $request->input('status');

            // 审核通过推到WMS
            if ($status == 4) {
                $data['order_id'] = $order_id;
                $data['k1'] = time();
                $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');

                $url = Config('website.api_domain').'order/wmsOrder';

                $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();

                    DB::beginTransaction();
                    try {
                        // 插入到order_price
                        $price['order_id'] = $order_id;
                        $price['order_sn'] = $orderInfo->order_sn;
                        $price['price_type'] = -1;
                        $price['price'] = '-'.$orderInfo->order_amount;
                        $price['create_time'] = time();

                        $priceAdd = DB::connection('order')->table('lie_order_price')->insert($price);

                        // 添加付款记录
                        $pay['user_id'] = $orderInfo->user_id; 
                        $pay['order_id'] = $order_id; 
                        $pay['order_sn'] = $orderInfo->order_sn; 
                        $pay['pay_id'] = 0; // 支付方式ID
                        $pay['pay_name'] = '交通银行'; // 支付方式名
                        $pay['pay_type'] = 1;
                        $pay['pay_amount'] = $orderInfo->order_amount;
                        $pay['is_paid'] = 1;
                        $pay['create_time'] = time();
                        $pay['pay_time'] = time();

                        $payLog = DB::connection('order')->table('lie_pay_log')->insert($pay);

朱继来's avatar
添加支付时间和取消时间
50b83220
 
朱继来 committed 6 years ago
611
                        // 待发货状态
朱继来's avatar
自营线下审核通过添加wms_syn
f8802936
 
朱继来 committed 6 years ago
612
                        $update = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->update(['status' => $status, 'pay_time' => time(), 'wms_syn' => 1]);
朱继来's avatar
添加支付时间和取消时间
50b83220
 
朱继来 committed 6 years ago
613

朱继来's avatar
调整新增自营线下订单
89258934
 
朱继来 committed 6 years ago
614 615 616 617 618 619 620 621 622 623 624 625
                        if ($update && $priceAdd && $payLog) {
                            DB::commit();
                        }
                    } catch (Exception $e) {
                        DB::rollBack();
                    }   
                } else {
                    return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
                }

                $event = '自营线下订单审核通过';
            } else {
朱继来's avatar
自营线下取消订单
862032e6
 
朱继来 committed 6 years ago
626 627
                $data['order_id'] = $request->input('order_id');
                $data['operator_id'] = $request->user->userId;
朱继来's avatar
整合前、后台取消订单、审核不通过接口
69260cac
 
朱继来 committed 6 years ago
628
                $data['type'] = 3;
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
629

朱继来's avatar
整合前、后台取消订单、审核不通过接口
69260cac
 
朱继来 committed 6 years ago
630
                $url = Config('website.api_domain').'order/cancel';
朱继来's avatar
自营线下取消订单
862032e6
 
朱继来 committed 6 years ago
631 632 633

                $data['k1']  = time();
                $data['k2']  = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
朱继来's avatar
整合前、后台取消订单、审核不通过接口
69260cac
 
朱继来 committed 6 years ago
634

朱继来's avatar
自营线下取消订单
862032e6
 
朱继来 committed 6 years ago
635 636 637 638 639
                $temp = json_decode(curlApi($url, $data, "POST"), true);

                $event = '自营线下订单审核不通过';

                return array('errcode'=>$temp['err_code'],'errmsg'=>$temp['err_msg']);
朱继来's avatar
调整新增自营线下订单
89258934
 
朱继来 committed 6 years ago
640
            }  
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
641
            
朱继来's avatar
调整新增自营线下订单
89258934
 
朱继来 committed 6 years ago
642 643 644 645 646 647 648 649 650 651 652 653 654 655
            // 操作记录
            $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);

            if (!$actionLog){
                errorLog(Error::E_ADD_FAILED, '添加操作记录失败');
                return ['errcode'=>Error::E_ADD_FAILED, 'errmsg'=>'添加操作记录失败'];
            } 

朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
656
            if (!empty($update)) {
朱继来's avatar
调整user_id
03a2741f
 
朱继来 committed 6 years ago
657
                return ['errcode' => 0, 'errmsg' => '操作成功'];
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
658
            } else {
朱继来's avatar
调整user_id
03a2741f
 
朱继来 committed 6 years ago
659
                return ['errcode' => -1, 'errmsg' => '操作失败'];
朱继来's avatar
自营线下订单
ad976e08
 
朱继来 committed 6 years ago
660 661 662 663
            }            
        }
    }

朱继来's avatar
temp
2c3fcf9a
 
朱继来 committed 6 years ago
664 665 666
    // 商品批量导入
    public function batchGoodsImport(Request $request)
    {
朱继来's avatar
temp1
f6580a64
 
朱继来 committed 6 years ago
667 668 669
        $file = $_FILES['file']; // $request->file('file')
        $filePath = $file['tmp_name']; // 临时路径

朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
670
        // 获取导入内容
朱继来's avatar
temp1
f6580a64
 
朱继来 committed 6 years ago
671 672 673 674
        $excel = [];
        Excel::load($filePath, function($reader) use(&$excel){
            $data = $reader->getSheet(0);
            $excel = $data->toArray();
朱继来's avatar
批量下单替换为CSV模板
c95f35bb
 
朱继来 committed 6 years ago
675 676
        }, 'GBK');
  
朱继来's avatar
添加模板导入校验
b1595353
 
朱继来 committed 6 years ago
677 678
        if (empty($excel)) return ['errcode' => 1, 'errmsg' => '未获取到模板内容,请检查模板内容数据格式'];

朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
679 680 681 682 683 684 685 686 687 688
        $type = $request->input('type'); // 1.联营 2.自营

        if ($type == 1) {
            $map = Config('params.joint_map');
            $type_val = '联营';
        } else {
            $map = Config('params.self_map');
            $type_val = '自营';
        }

朱继来's avatar
1. 调整日志;
97fb1f12
 
朱继来 committed 6 years ago
689 690 691 692
        if (count($map) != count($excel[0])) {
            errorLog(Error::E_IMPORT_TEMP_ERR, '导入模板错误,需导入'.$type_val.'模板');
            return ['errcode' => 1, 'errmsg' => '导入模板错误,需导入'.$type_val.'模板'];
        }
朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
693

朱继来's avatar
批量下单替换为CSV模板
c95f35bb
 
朱继来 committed 6 years ago
694 695
        $excel = $this->handleData($excel, $map); // 处理数据

朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
696 697 698 699
        // 验证excel内容
        $valid = $this->excelValid($excel); 

        if ($valid['errcode'] != 0) {
朱继来's avatar
1. 调整日志;
97fb1f12
 
朱继来 committed 6 years ago
700
            errorLog(Error::E_IMPORT_VALID_FAILED, $valid['errmsg']);
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
701 702 703 704 705 706
            return $valid;
        }

        array_shift($excel); // 删除第一行

        // 推送到API
朱继来's avatar
批量下单替换为CSV模板
c95f35bb
 
朱继来 committed 6 years ago
707
        $data['data'] = $excel;
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
708
        $data['operator_id'] = $request->user->userId;
朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
709
        $data['type'] = 3; // 后台批量添加标记
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
710 711 712
        $data['uid'] = $request->input('user_id'); 
        $data['delivery_place'] = $request->input('delivery_place'); 

朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
713 714 715 716 717 718
        if ($type == 1) { // 联营
            $url = Config('website.api_domain').'cart/addBatchByOrderSystem';
        } else {
            $url = Config('website.api_domain').'cart/addBatch';
        }
        
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
719 720
        $data['k1']  = time();
        $data['k2']  = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
721

朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
722 723 724
        $temp = json_decode(curlApi($url, $data, "POST"), true);

        return ['errcode' => $temp['err_code'], 'errmsg' => $temp['err_msg']];
朱继来's avatar
temp1
f6580a64
 
朱继来 committed 6 years ago
725 726 727
    }

    // 验证导入excel
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
728
    public function excelValid($excel)
朱继来's avatar
temp1
f6580a64
 
朱继来 committed 6 years ago
729 730 731 732 733
    {
        $count = count($excel);

        if ($count == 1) return ['errcode' => 1, 'errmsg' => '未填写物料信息'];

朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
        // 获取excel菜单栏必填项
        $required = array_filter($excel[0], function($v) {
            return strpos($v, '*') === false ? false : true;
        });

        $required_keys = array_keys($required); // 必填项keys   

        $err = ['errcode' => 0, 'errmsg' => '验证成功']; // 提示信息
        array_walk($excel, function($val, $key) use($required, $required_keys, &$err) {
            // 跳过第一条
            if ($key != 0) {
                foreach ($val as $k=>$v) {
                    if (in_array($k, $required_keys)) {
                        if (empty($v)) { // 若必填项值为空,返回提示信息
                            $err = ['errcode' => 1, 'errmsg' => $required[$k].'列,第'.$key.'行不能为空']; 
                            break;
                        }
                    }
朱继来's avatar
批量下单替换为CSV模板
c95f35bb
 
朱继来 committed 6 years ago
752 753 754 755 756 757 758 759

                    // 自营ID、采购数量和单价为数字类型
                    if ($k == 'id' || $k == 'num' || $k == 'goods_price') {
                        if (!preg_match('/\d/', $v)) {
                            $err = ['errcode' => 2, 'errmsg' => $required[$k].'列,第'.$key.'行格式错误']; 
                            break;
                        }        
                    }
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
760 761 762 763 764
                } 
            }
        });
        
        return $err;
朱继来's avatar
temp
2c3fcf9a
 
朱继来 committed 6 years ago
765 766
    }

朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
767
    // 处理导入内容---赋上字段
朱继来's avatar
批量添加物料
698861e8
 
朱继来 committed 6 years ago
768
    public function handleData($excel, $map)
朱继来's avatar
temp2
6eaed4b6
 
朱继来 committed 6 years ago
769 770 771 772 773 774 775 776 777 778 779
    {
        $goods_info = array_map(function($val) use($map) {
            foreach ($val as $k=>$v) {
                $tmp[$map[$k]] = $v;
            }

            return $tmp;
        }, $excel);

        return $goods_info;
    }
朱继来's avatar
调整线上下单
0d9ade8b
 
朱继来 committed 5 years ago
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797

    // 添加商品到订单
    public function addGoods(Request $request)
    {
        if ($request->isMethod('post')) {
            $data['order_id']    = $request->input('order_id');
            $data['goods_id']    = $request->input('goods_id');
            $data['goods_num']   = $request->input('goods_num');
            $data['operator_id'] = $request->user->userId;

            $url = Config('website.order_api_domain').'/order/addgoods';

            $response = json_decode(curlApi($url, $data, 'post'), true); 

            return ['errcode' => $response['errcode'], 'errmsg' => $response['errmsg']];
        }
    }

朱继来's avatar
暂存
bf9e86a3
 
朱继来 committed 6 years ago
798
}