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
BlameHistoryPermalink
Switch branch/tag
  • Order
  • app
  • Http
  • Controllers
  • ApiController.php
  • 朱继来's avatar
    调整列表生产跟踪 · c6c7ce66
    朱继来 committed 4 years ago
    c6c7ce66
ApiController.php 13.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Model\PaymentDaysModel;
use App\Model\Pcb\PcbOrderModel;
use App\Model\Pcb\PcbPublicModel;
use App\Model\Pcb\PcbPurchaseModel;
use App\Model\Pcb\PcbServerModel;
use App\Model\KefuModel;
use App\Model\CmsModel;
use App\Model\OrderModel;
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\BrandBlackListModel;
use App\Model\PayExtendModel;
use Illuminate\Support\Facades\Redis;
use App\Model\ShoppingCartModel;

class ApiController extends Controller
{
    public function Entrance(Request $request, $id ){
        $this->$id($request, $id);
    }

    private function Export($errcode=0,$errmsg='成功',$data=''){
        if(is_array($errcode)){
            ErrorLog($errcode[0],$errcode[1]);
            echo json_encode(['errcode'=>$errcode[0],'errmsg'=>$errcode[1],'data'=>!empty($errcode[2])?$errcode[2]:'']);
            exit();
        }else{
            ErrorLog($errcode,$errmsg);
            echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data]);
            exit();
        }
    }

    private function ExportLayui($errcode=0,$errmsg=0,$data=[],$count=0,$total=''){
        if(is_array($errcode)){
            ErrorLog($errcode[0],$errcode[1]);
            echo json_encode(['code'=>$errcode[0],'msg'=>$errcode[1],'data'=>$errcode[2],'count'=>$errcode[3],'total'=>!empty($errcode[4])?$errcode[4]:'']);
        }else{
            ErrorLog($errcode,$errmsg);
            echo json_encode(['code'=>$errcode,'msg'=>$errmsg,'data'=>$data,'count'=>$count,'total'=>$total]);
        }
        exit();
    }

    private function ApiPaymentDaysList(){
        $Model=new PaymentDaysModel();
        $this->ExportLayui($Model->ApiPaymentDaysList());
    }

    private function ApiAuthPaymentDays($request){
        $Model=new PaymentDaysModel();
        $this->Export($Model->ApiAuthPaymentDays($request->user->userId));
    }
    //pcb订单列表
    private function ApiPcbOrderList($request){
        $this->ExportLayui((new PcbOrderModel())->getList());
    }
    //pcb订单列表导出
    private function ApiPcbOrderListExport($request){
        ((new PcbOrderModel())->export());
    }
    //pcb客服点击确定发货
    private function ApiSendStock($request){
        $this->Export((new PcbPublicModel())->orderShipping($request->user->userId,$request->all()));
    }
    //pcb客服点击转采购
    private function ApiAddPurchase($request){
        echo (new PcbServerModel())->AddPurchase($request->user->userId,$request->input("order_id"));
    }
    //pcb客服审核订单,反馈给前台
    private function ApiAuditOrder($request){
        $this->Export((new PcbPublicModel())->auditOrder($request->user->userId,$request->input("order_id"),$request->input("order_sn"),$request->input("content")));
    }
    //pcb订单列表
    private function ApiPcbPurchaseList($request){
        $this->ExportLayui((new PcbPurchaseModel())->getList());
    }
    //pcb订单列表导出
    private function ApiPcbPurchaseListExport($request){
        ((new PcbPurchaseModel())->export());
    }
    //pcb后台点击采购确认
    private function ApiConfirmOrder($request){
       echo  (new PcbServerModel())->confirmOrder($request->user->userId,$request->input("purchase_id"),$request->input("status"));
    }
    //pcb后台点击采购确认
    private function ApiOfflinePay($request){
        echo  (new PcbServerModel())->offlinePay($request->user->userId,$request->input("order_id"),$request->input("pay_money"));
    }
    //pcb后台点击采购确认
    private function ApiSetOrderProduct($request){
        echo  (new PcbServerModel())->setOrdserProduct($request->user->userId,$request->input("purchase_id"));
    }

    // 获取客服池
    public function ApiKefuList($request)
    {   
        $KefuModel = new KefuModel;
        $this->ExportLayui($KefuModel->lists($request));
    }

    // 新增客服
    public function ApiAddKefu($request)
    {
        $KefuModel = new KefuModel;
        $this->Export($KefuModel->add($request));
    }

    // 编辑客服
    public function ApiEditKefu($request)
    {
        $KefuModel = new KefuModel;
        $this->Export($KefuModel->edit($request));
    }

    // 删除客服
    public function ApiDelKefu($request)
    {
        $KefuModel = new KefuModel;
        $this->Export($KefuModel->del($request));
    }

    // 置顶客服
    public function ApiTopKefu($request)
    {
        $KefuModel = new KefuModel;
        $this->Export($KefuModel->top($request));
    }

    // 获取订单明细
    public function getOrderItems($request)
    {
        $order_id = $request->input('order_id');

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

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

        $userData = array("order_id"=>$order_id, "type"=>3, "k1"=>$data['k1'], "k2"=>$data['k2']);

        $resp = json_decode(curlApi($url, $userData, "POST"), true);

        $this->Export(0, '',  $resp['data']['order_items_info']);
    }

    // 获取订单跟踪
    public function getOrderItemsTrack($request)
    {
        $rec_id = $request->input('rec_id'); 

        // $OrderItemsTrackModel = new OrderItemsTrackModel;
        // $track = $OrderItemsTrackModel->getLastItemTrack($rec_id);

        // if (!$track) $this->Export(1, '无跟踪明细');

        // $data = $track['track_content'].',数量:'.$track['track_num'];

        $OrderItemsTrackingModel = new OrderItemsTrackingModel;
        $track = $OrderItemsTrackingModel->getLastItemTrack($rec_id);

        if (!$track) $this->Export(1, '无跟踪明细');

        $data = $track['msg'].',状态:'.$track['status_cn'];

        $this->Export(0, '',  $data);
    }

    // 获取自营样片领取列表
    public function ApiSelfSampleList($request)
    {
        $UserSampleApplyModel = new UserSampleApplyModel;
        $this->ExportLayui($UserSampleApplyModel->lists($request));
    }

    // 获取自营样片领取记录
    public function ApiSelfSampleApplyLog($request)
    {
        $UserSampleApplyModel = new UserSampleApplyModel;
        $this->ExportLayui($UserSampleApplyModel->applyLog($request));
    }

    // 获取自营样片邀约记录
    public function ApiSelfSampleInviteLog($request)
    {
        $UserSampleInviteModel = new UserSampleInviteModel;
        $this->ExportLayui($UserSampleInviteModel->lists($request));
    }

    /*
        修改订单详情
    */
    public function update_order_items($request)
    {
        $data['order_id']    = $request->input('edit_order_id');
        $data['change_item'] = $request->input('change_item');
        $data['operator_id'] = $request->user->userId;

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

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

        $temp = json_decode(curlApi($url, $data, "POST"), true); // 连接API

        $this->Export($temp['err_code'], $temp['err_msg']);
    }

    /*
        检查内部系统用户是否存在
    */
    public function check_user_exists($request){

         $CmsModel = new CmsModel();

         $userName = $request->input('user');

         $user_info = $CmsModel->getUserInfo(array('name'=>$userName));

        if($user_info){
            $this->Export(1, 'success',$user_info['userId']);
        }else{
            $this->Export(-1, 'error');
        }
    }

    // 获取团购信息
    public function ApiGroupList($request)
    {
        $UserGroupModel = new UserGroupModel;
        $this->ExportLayui($UserGroupModel->lists($request));
    }

    // 获取品牌黑名单
    public function ApiBrandBlackList($request)
    {
        $BrandBlackListModel = new BrandBlackListModel;
        $this->ExportLayui($BrandBlackListModel->lists($request));
    }

    // 新增/编辑品牌黑名单
    public function ApiSetBrandBlackList($request) 
    {
        $BrandBlackListModel = new BrandBlackListModel;
        $this->Export($BrandBlackListModel->setBlackList($request));
    }

    // 删除品牌黑名单
    public function ApiDelBrandBlackList($request) 
    {
        $BrandBlackListModel = new BrandBlackListModel;
        $this->Export($BrandBlackListModel->delBlackList($request));
    }

    // 启用/禁用品牌黑名单
    public function ApiActionBrandBlackList($request) 
    {
        $BrandBlackListModel = new BrandBlackListModel;
        $this->Export($BrandBlackListModel->action($request));
    }

    // 自营申请收款
    public function ajaxApplyPaid($request) 
    {
        $PayExtendModel = new PayExtendModel;
        $this->Export($PayExtendModel->setPay($request));
    }

    // 获取品牌库列表
    public function getStandardBrandList($request)
    {
        $standard_brand_name = $request->input('standard_brand_name', '');

        // 搜索指定品牌
        if ($standard_brand_name) {
            $res = $this->apiStandardBrandList($standard_brand_name);

            $this->ExportLayui(0, '', $res['data'], count($res['data']));
        }
        
        $s_key = Config('config.s_standard_brand');
        $data = Redis::get($s_key);

        // 无缓存情况下
        if (!$data) {
            $res = $this->apiStandardBrandList();
            $data = json_encode($res['data']);

            $expire = Config('config.s_standard_brand_expire');
            Redis::setex($s_key, $expire, $data);
        }

        $data = json_decode($data, true);

        $this->ExportLayui(0, '', $data, count($data));
    }

    public function apiStandardBrandList($standard_brand_name='')
    {
        $url = Config('config.footstone_url').'/AuthApi/get_scm_brand_list';
        $key = Config('config.auth_key');

        $standard_brand_name && $map['erp_brand_name'] = $standard_brand_name;

        $map['time']     = time();
        $map['AuthSign'] = MD5(MD5(http_build_query($map)) . $key);

        $data['data'] = $map;

        return json_decode(curlApi($url, $data, 'post'), true);
    }

    // 绑定品牌
    public function apiBindStandardBrand($request)
    {
        $type            = $request->input('type', 1);
        $cart_id         = $request->input('cart_id', 0);
        $curr_brand_id   = $request->input('curr_brand_id', 0);
        $curr_brand_name = $request->input('curr_brand_name', '');
        $scm_brand_id    = $request->input('scm_brand_id', 0);
        $scm_brand_name  = $request->input('scm_brand_name', '');

        if (!$scm_brand_id) $this->Export(1, '参数缺失');

        if ($type == 1 && !$cart_id) $this->Export(1, '当前行购物车ID缺失');

        $url = Config('config.footstone_url').'/AuthApi/binding_scm_brand';
        $key = Config('config.auth_key');

        $map['time']         = time();
        $map['scm_brand_id'] = $scm_brand_id;
        $map['brand_id']     = [$curr_brand_id];
        $map['brand_name']   = [$curr_brand_name];
        $map['admin_id']     = $request->user->userId;
        $map['admin_name']   = $request->user->name;
        $map['AuthSign']     = MD5(MD5(http_build_query($map)) . $key);

        $data['data'] = $map;

        $res = json_decode(curlApi($url, $data, 'post'), true);
        
        if ($res['errcode'] != 0) $this->Export($res['errcode'], $res['errmsg']);

        $save = [];
        $save['standard_brand_id']   = $scm_brand_id;
        $save['standard_brand_name'] = $scm_brand_name;

        // 将标准品牌添加到购物车
        if ($type == 1) {
            $ShoppingCartModel = new ShoppingCartModel;
            $res = $ShoppingCartModel->where('cart_id', $cart_id)->update($save);

            if ($res === false) $this->Export(1, '更新标准品牌失败');
        } 
        
        $this->Export(0, '更新标准品牌成功');
    }

    public function pushWms($request)
    {
        $order_sn = $request->input('order_sn', '');

        $url = Config('website.pur_url').'/server/wms2?order_sn='.$order_sn;

        $res = curlApi($url);

        $this->Export(0, '成功', $res);
    }

    // 编辑ERP单号
    public function edit_erp_sn($request)
    {
        $order_id = $request->input('order_id');
        $erp_sn   = $request->input('erp_sn');

        $OrderExtendModel = new OrderExtendModel;
        $OrderActionLogModel = new OrderActionLogModel;

        $order_extend = $OrderExtendModel->where('order_id', $order_id)->first();

        if (!$order_extend) {
            $res = $OrderExtendModel->insert(['order_id' => $order_id, 'erp_sn' => $erp_sn]);

            $OrderActionLogModel->addLog($order_id, $request->user->userId, 2, '编辑ERP单号,添加订单扩展表');
        } else {
            $res = $OrderExtendModel->where('order_id', $order_id)->update(['erp_sn' => $erp_sn]);

            $OrderActionLogModel->addLog($order_id, $request->user->userId, 2, '编辑ERP单号,修改前:'.$order_extend->erp_sn);
        }

        if ($res === false) {
            $this->Export(-1, '编辑ERP单号失败');
        }    

        $this->Export(0, '编辑ERP单号成功');
    }

    // 手动推送到ERP,标记erp_syn=1
    public function syn_erp($request) 
    {
        $order_id = $request->input('order_id');

        $OrderModel = new OrderModel;

        $res = $OrderModel->where('order_id', $order_id)->update(['erp_syn' => 1]);

        if ($res === false) $this->Export(-1, '更新失败');

        $this->Export(0, '成功');
    }


}