作者 耿培杰

接口开发

1 /nbproject/ 1 /nbproject/
2 /runtime/* 2 /runtime/*
3 /public/uploads/* 3 /public/uploads/*
  4 +/application/database.php
4 .idea 5 .idea
5 composer.lock 6 composer.lock
6 *.log 7 *.log
  1 +<?php
  2 +
  3 +namespace addons\kdniao;
  4 +
  5 +use app\common\library\Menu;
  6 +use think\Addons;
  7 +
  8 +/**
  9 + * 插件
  10 + */
  11 +class Kdniao extends Addons
  12 +{
  13 +
  14 + /**
  15 + * 插件安装方法
  16 + * @return bool
  17 + */
  18 + public function install()
  19 + {
  20 +
  21 + return true;
  22 + }
  23 +
  24 + /**
  25 + * 插件卸载方法
  26 + * @return bool
  27 + */
  28 + public function uninstall()
  29 + {
  30 +
  31 + return true;
  32 + }
  33 +
  34 + /**
  35 + * 插件启用方法
  36 + * @return bool
  37 + */
  38 + public function enable()
  39 + {
  40 + Menu::enable('kdniao');
  41 + return true;
  42 + }
  43 +
  44 + /**
  45 + * 插件禁用方法
  46 + * @return bool
  47 + */
  48 + public function disable()
  49 + {
  50 + Menu::disable('kdniao');
  51 + return true;
  52 + }
  53 +
  54 +}
  1 +if ($('.kdniao').length > 0) {
  2 +
  3 + $('.kdniao').each(function () {
  4 + var code = $(this).data('code');
  5 +
  6 + $(this).addClass('btn btn-xs bg-success').append('<i class="fa fa-truck"></i>' + code);
  7 + });
  8 +
  9 + $('.kdniao').click(function () {
  10 + var company = $(this).data('company');
  11 + var code = $(this).data('code');
  12 +
  13 + if (company && code) {
  14 + Layer.open({
  15 + type: 2,
  16 + area: ['700px', '450px'],
  17 + fixed: false, //不固定
  18 + maxmin: true,
  19 + content: '/addons/kdniao/index/query?company=' + company + '&code=' + code
  20 + });
  21 + }
  22 + });
  23 +}
  1 +<?php
  2 +
  3 +return array (
  4 + 0 =>
  5 + array (
  6 + 'name' => 'EBusinessID',
  7 + 'title' => '商户ID',
  8 + 'type' => 'string',
  9 + 'content' =>
  10 + array (
  11 + ),
  12 + 'value' => '1637658',
  13 + 'rule' => 'required',
  14 + 'msg' => '',
  15 + 'tip' => '',
  16 + 'ok' => '',
  17 + 'extend' => '',
  18 + ),
  19 + 1 =>
  20 + array (
  21 + 'name' => 'AppKey',
  22 + 'title' => 'AppKey',
  23 + 'type' => 'string',
  24 + 'content' =>
  25 + array (
  26 + ),
  27 + 'value' => 'd49772b1-339f-4641-ab29-5346ad2e4403',
  28 + 'rule' => 'required',
  29 + 'msg' => '',
  30 + 'tip' => '',
  31 + 'ok' => '',
  32 + 'extend' => '',
  33 + ),
  34 + 2 =>
  35 + array (
  36 + 'name' => 'ReqURL',
  37 + 'title' => 'API请求地址',
  38 + 'type' => 'string',
  39 + 'content' =>
  40 + array (
  41 + ),
  42 + 'value' => 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx',
  43 + 'rule' => 'required',
  44 + 'msg' => '',
  45 + 'tip' => '',
  46 + 'ok' => '',
  47 + 'extend' => '',
  48 + ),
  49 +);
  1 +<?php
  2 +
  3 +namespace addons\kdniao\controller;
  4 +
  5 +use addons\kdniao\library\Kdniao;
  6 +use think\addons\Controller;
  7 +use think\Db;
  8 +use think\response\Json;
  9 +
  10 +class Index extends Controller
  11 +{
  12 +
  13 + public function index()
  14 + {
  15 + if ($this->request->isPost()) {
  16 + $code = $this->request->post('code');
  17 + $company = $this->request->post('company');
  18 + $kdniao = new Kdniao();
  19 +
  20 + $wuliu = $kdniao->getOrderTracesByJson($company, $code);
  21 +
  22 + if ($wuliu == -1) {
  23 + $json = [
  24 + 'code' => 0,
  25 + 'msg' => '未设置接口配置!请在插件管理中配置!',
  26 + 'data' => '',
  27 + ];
  28 + return Json($json);
  29 + }
  30 +
  31 + $wuliu = json_decode($wuliu, true);
  32 +
  33 + $json = [
  34 + 'code' => 1,
  35 + 'msg' => '获取成功',
  36 + 'data' => isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]]
  37 + ];
  38 + //物流信息倒序
  39 + return Json($json);
  40 + } else {
  41 + $data = Db::name('kdniao')->select();
  42 + $this->assign('data', $data);
  43 + return $this->view->fetch();
  44 + }
  45 + }
  46 +
  47 + /**
  48 + * 查询
  49 + */
  50 + public function query()
  51 + {
  52 + $code = $this->request->param('code');
  53 + $company = $this->request->param('company');
  54 +
  55 + $kdniao = new Kdniao();
  56 + $wuliu = $kdniao->getOrderTracesByJson($company, $code);
  57 +
  58 + $wuliu = json_decode($wuliu, true);
  59 +
  60 + /*if (isset($wuliu['Traces']) && count($wuliu['Traces'])) {
  61 + $this->assign('data', array_reverse($wuliu['Traces']));
  62 + }*/
  63 +
  64 + $this->assign('data', isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : '');
  65 + return $this->view->fetch();
  66 + }
  67 +
  68 +}
  1 +name = kdniao
  2 +title = 快递鸟
  3 +intro = 快递鸟API物流即时信息查询插件
  4 +author = Coder
  5 +website = http://www.kdniao.com
  6 +version = 1.0.1
  7 +state = 1
  8 +url = /addons/kdniao.html
  1 +
  2 +CREATE TABLE IF NOT EXISTS `__PREFIX__kdniao` (
  3 + `company` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
  4 + `code` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ''
  5 +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='快递鸟物流编码表';
  6 +
  7 +
  8 +BEGIN;
  9 +INSERT INTO `__PREFIX__kdniao` (`company`, `code`) VALUES
  10 +('顺丰速运', 'SF'),
  11 +('百世快递', 'HTKY'),
  12 +('中通快递', 'ZTO'),
  13 +('申通快递', 'STO'),
  14 +('圆通速递', 'YTO'),
  15 +('韵达速递', 'YD'),
  16 +('邮政快递包裹', 'YZPY'),
  17 +('EMS', 'EMS'),
  18 +('天天快递', 'HHTT'),
  19 +('京东快递', 'JD'),
  20 +('优速快递', 'UC'),
  21 +('德邦快递', 'DBL'),
  22 +('宅急送', 'ZJS'),
  23 +('TNT快递', 'TNT'),
  24 +('UPS', 'UPS'),
  25 +('DHL', 'DHL'),
  26 +('FEDEX联邦(国内件)', 'FEDEX'),
  27 +('FEDEX联邦(国际件)', 'FEDEX_GJ');
  28 +COMMIT;
  1 +<?php
  2 +
  3 +namespace addons\kdniao\library;
  4 +
  5 +class Kdniao
  6 +{
  7 + protected $config = [];
  8 +
  9 + public function __construct($options = [])
  10 + {
  11 + if ($config = get_addon_config('kdniao')) {
  12 + $this->config = array_merge($this->config, $config);
  13 + }
  14 + $this->config = array_merge($this->config, is_array($options) ? $options : []);
  15 + }
  16 +
  17 + /**
  18 + * Json方式 查询订单物流轨迹
  19 + * @param string $shipper
  20 + * @param string $code
  21 + * @return int|string
  22 + */
  23 + public function getOrderTracesByJson($shipper, $code)
  24 + {
  25 + $eBusinessID = $this->config["EBusinessID"];
  26 + $appKey = $this->config["AppKey"];
  27 + $reqURL = $this->config["ReqURL"];
  28 +
  29 + if (!$eBusinessID || !$appKey || !$reqURL) {
  30 + return -1;
  31 + }
  32 +
  33 + $requestData = "{'OrderCode':'','ShipperCode':'$shipper','LogisticCode':'$code'}";
  34 +
  35 + $datas = array(
  36 + 'EBusinessID' => $eBusinessID,
  37 + 'RequestType' => '1002',
  38 + 'RequestData' => urlencode($requestData),
  39 + 'DataType' => '2',
  40 + );
  41 + $datas['DataSign'] = $this->encrypt($requestData, $appKey);
  42 + $result = $this->sendPost($reqURL, $datas);
  43 +
  44 + //根据公司业务处理返回的信息......
  45 +
  46 + return $result;
  47 + }
  48 +
  49 + /**
  50 + * Post提交数据
  51 + * @param string $url 请求Url
  52 + * @param array $datas 提交的数据
  53 + * @return string 响应返回的html
  54 + */
  55 + protected function sendPost($url, $datas)
  56 + {
  57 + $temps = array();
  58 + foreach ($datas as $key => $value) {
  59 + $temps[] = sprintf('%s=%s', $key, $value);
  60 + }
  61 + $post_data = implode('&', $temps);
  62 + $url_info = parse_url($url);
  63 + if (empty($url_info['port'])) {
  64 + $url_info['port'] = 80;
  65 + }
  66 + $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  67 + $httpheader .= "Host:" . $url_info['host'] . "\r\n";
  68 + $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
  69 + $httpheader .= "Content-Length:" . strlen($post_data) . "\r\n";
  70 + $httpheader .= "Connection:close\r\n\r\n";
  71 + $httpheader .= $post_data;
  72 + $fd = fsockopen($url_info['host'], $url_info['port']);
  73 + fwrite($fd, $httpheader);
  74 + $gets = "";
  75 + $headerFlag = true;
  76 + while (!feof($fd)) {
  77 + if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  78 + break;
  79 + }
  80 + }
  81 + while (!feof($fd)) {
  82 + $gets .= fread($fd, 128);
  83 + }
  84 + fclose($fd);
  85 +
  86 + return $gets;
  87 + }
  88 +
  89 + /**
  90 + * 电商Sign签名生成
  91 + * @param string 内容
  92 + * @param string Appkey
  93 + * @return string DataSign签名
  94 + */
  95 + protected function encrypt($data, $appkey)
  96 + {
  97 + return urlencode(base64_encode(md5($data . $appkey)));
  98 + }
  99 +}
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>快递鸟物流即时信息查询 - {$site.name}</title>
  5 + <meta charset="UTF-8">
  6 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7 +
  8 + <!-- Bootstrap Core CSS -->
  9 + <link rel="stylesheet" href="__CDN__/assets/libs/bootstrap/dist/css/bootstrap.min.css">
  10 +
  11 + <style>
  12 + .track_list {
  13 + padding: 10px;
  14 + list-style: none;
  15 + }
  16 +
  17 + .track_list li {
  18 + font-size: 14px;
  19 + border-left: 1px solid #dcdcdc;
  20 + padding-bottom: 10px;
  21 + padding-left: 15px;
  22 + position: relative
  23 + }
  24 +
  25 + .track_list li p.time {
  26 + font-size: 11px;
  27 + padding-bottom: 10px;
  28 + border-bottom: 1px solid #e7e7e7
  29 + }
  30 +
  31 + .track_list li p:first-child {
  32 + padding-bottom: 5px
  33 + }
  34 +
  35 + .track_list li.now p {
  36 + color: #00bb42
  37 + }
  38 +
  39 + .track_list li.old p {
  40 + color: #9d9d9d
  41 + }
  42 +
  43 + .track_list li.now .ico {
  44 + display: block;
  45 + position: absolute;
  46 + left: -8px;
  47 + top: 0;
  48 + width: 16px;
  49 + height: 16px;
  50 + background-color: #b0ffd4;
  51 + border-radius: 8px
  52 + }
  53 +
  54 + .track_list li.now .ico i {
  55 + display: block;
  56 + width: 12px;
  57 + height: 12px;
  58 + background-color: #00aa2c;
  59 + border-radius: 6px;
  60 + position: absolute;
  61 + left: 2px;
  62 + top: 2px
  63 + }
  64 +
  65 + .track_list li.old .ico {
  66 + display: block;
  67 + width: 10px;
  68 + height: 10px;
  69 + background-color: #dcdcdc;
  70 + border-radius: 5px;
  71 + position: absolute;
  72 + left: -5px;
  73 + top: 4px
  74 + }
  75 +
  76 + .track_list li:last-child {
  77 + border-left: 0
  78 + }
  79 +
  80 + .track_list li:last-child .time {
  81 + border-bottom: 0
  82 + }
  83 +
  84 + .track_list li:last-child.old .ico {
  85 + left: -4px;
  86 + top: 0
  87 + }
  88 +
  89 + .logistics_track .nofound {
  90 + padding: 30px 10px;
  91 + line-height: 20px;
  92 + font-size: 12px;
  93 + color: #9b9b9b
  94 + }
  95 +
  96 + .track_list li p a {
  97 + color: #0d90ff
  98 + }
  99 + </style>
  100 + <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  101 + <!--[if lt IE 9]>
  102 + <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  103 + <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
  104 + <![endif]-->
  105 +
  106 +</head>
  107 +<body>
  108 +<div class="container">
  109 + <h2>快递鸟物流即时信息查询</h2>
  110 + <hr>
  111 + <form action="" class="form-horizontal">
  112 + <fieldset>
  113 + <div class="form-group">
  114 + <label class="col-lg-1 control-label">物流公司</label>
  115 + <div class="col-lg-11">
  116 + <select id="company" name="company" class="form-control">
  117 + <option value="">--请选择--</option>
  118 + {volist name="data" id="vo"}
  119 + <option value="{$vo.code}">{$vo.company}</option>
  120 + {/volist}
  121 + </select>
  122 + </div>
  123 + </div>
  124 +
  125 + <div class="form-group">
  126 + <label class="col-lg-1 control-label">快递编号</label>
  127 + <div class="col-lg-11">
  128 + <input type="text" class="form-control" id="code" name="code" placeholder="快递编号">
  129 + </div>
  130 + </div>
  131 +
  132 + <div class="form-group">
  133 + <div class="col-lg-11 col-lg-offset-1">
  134 + <button type="button" id="btnsend" name="btnsend" class="btn btn-primary">发送</button>
  135 + <button type="reset" class="btn btn-default">重置</button>
  136 + </div>
  137 + </div>
  138 + </fieldset>
  139 + </form>
  140 +
  141 + <div class="well">
  142 + <div class="row">
  143 + <blockquote>物流数据:</blockquote>
  144 + <ul class="track_list">
  145 +
  146 + </ul>
  147 + </div>
  148 + </div>
  149 +</div>
  150 +<!-- jQuery -->
  151 +<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
  152 +
  153 +<script type="text/javascript">
  154 + $("#btnsend").click(function () {
  155 + $.ajax({
  156 + type: "post",
  157 + url: "{:addon_url('kdniao/index/index')}",
  158 + data: {company: $("#company").val(), code: $("#code").val(), r: Math.random()},
  159 + success: function (data) {
  160 + console.log(data);
  161 + $('.track_list').html('');
  162 +
  163 + if (data.code) {
  164 + $.each(data.data, function (i, n) {
  165 + var $li = $('<li class="' + (i == 0 ? 'now' : 'old') + '">' +
  166 + '<p>' + n.AcceptStation + '</p>' +
  167 + '<p>' + n.AcceptTime + '</p>' +
  168 + '<span class="ico"><i></i></span>' +
  169 + '</li>');
  170 + $('.track_list').append($li);
  171 + });
  172 + } else {
  173 + var $li = $('<li>' +
  174 + '<b>' + data.msg + '</b>' +
  175 + '</li>');
  176 + $('.track_list').append($li);
  177 + }
  178 +
  179 + },
  180 + error: function () {
  181 + alert('查询失败');
  182 + },
  183 + complete: function () {
  184 +
  185 + }
  186 + });
  187 + });
  188 +</script>
  189 +</body>
  190 +</html>
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>快递鸟物流即时信息查询 - {$site.name}</title>
  5 + <meta charset="UTF-8">
  6 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7 +
  8 + <!-- Bootstrap Core CSS -->
  9 + <link rel="stylesheet" href="__CDN__/assets/libs/bootstrap/dist/css/bootstrap.min.css">
  10 +
  11 + <style>
  12 + .track_list {
  13 + padding: 10px;
  14 + list-style: none;
  15 + }
  16 +
  17 + .track_list li {
  18 + font-size: 14px;
  19 + border-left: 1px solid #dcdcdc;
  20 + padding-bottom: 10px;
  21 + padding-left: 15px;
  22 + position: relative
  23 + }
  24 +
  25 + .track_list li p.time {
  26 + font-size: 11px;
  27 + padding-bottom: 10px;
  28 + border-bottom: 1px solid #e7e7e7
  29 + }
  30 +
  31 + .track_list li p:first-child {
  32 + padding-bottom: 5px
  33 + }
  34 +
  35 + .track_list li.now p {
  36 + color: #00bb42
  37 + }
  38 +
  39 + .track_list li.old p {
  40 + color: #9d9d9d
  41 + }
  42 +
  43 + .track_list li.now .ico {
  44 + display: block;
  45 + position: absolute;
  46 + left: -8px;
  47 + top: 0;
  48 + width: 16px;
  49 + height: 16px;
  50 + background-color: #b0ffd4;
  51 + border-radius: 8px
  52 + }
  53 +
  54 + .track_list li.now .ico i {
  55 + display: block;
  56 + width: 12px;
  57 + height: 12px;
  58 + background-color: #00aa2c;
  59 + border-radius: 6px;
  60 + position: absolute;
  61 + left: 2px;
  62 + top: 2px
  63 + }
  64 +
  65 + .track_list li.old .ico {
  66 + display: block;
  67 + width: 10px;
  68 + height: 10px;
  69 + background-color: #dcdcdc;
  70 + border-radius: 5px;
  71 + position: absolute;
  72 + left: -5px;
  73 + top: 4px
  74 + }
  75 +
  76 + .track_list li:last-child {
  77 + border-left: 0
  78 + }
  79 +
  80 + .track_list li:last-child .time {
  81 + border-bottom: 0
  82 + }
  83 +
  84 + .track_list li:last-child.old .ico {
  85 + left: -4px;
  86 + top: 0
  87 + }
  88 +
  89 + .logistics_track .nofound {
  90 + padding: 30px 10px;
  91 + line-height: 20px;
  92 + font-size: 12px;
  93 + color: #9b9b9b
  94 + }
  95 +
  96 + .track_list li p a {
  97 + color: #0d90ff
  98 + }
  99 + </style>
  100 + <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  101 + <!--[if lt IE 9]>
  102 + <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  103 + <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
  104 + <![endif]-->
  105 +
  106 +</head>
  107 +<body>
  108 +<div class="container">
  109 + <div class="well">
  110 + <div class="row">
  111 + <blockquote>物流数据:</blockquote>
  112 + <ul class="track_list">
  113 + {volist name="data" id="item" empty="暂无物流信息"}
  114 + <li class='{if condition="$i eq 1"}now{else/}old{/if}'>
  115 + <p>{$item.AcceptStation}</p>
  116 + <p>{$item.AcceptTime}</p>
  117 + <span class="ico"><i></i></span>
  118 + </li>
  119 + {/volist}
  120 + </ul>
  121 + </div>
  122 + </div>
  123 +</div>
  124 +<!-- jQuery -->
  125 +<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
  126 +
  127 +
  128 +</body>
  129 +</html>
@@ -173,4 +173,32 @@ function setArr($data) @@ -173,4 +173,32 @@ function setArr($data)
173 $new_arr[$tmp][$k] = $goodsDepot; 173 $new_arr[$tmp][$k] = $goodsDepot;
174 } 174 }
175 return $new_arr; 175 return $new_arr;
  176 +}
  177 +
  178 +/**
  179 + * 快递100查询物流轨迹
  180 + * @param $code
  181 + * @param $company
  182 + * @return mixed
  183 + */
  184 +function kuaidi100_query($code,$company){
  185 + require_once EXTEND_PATH . 'kuaidi100/query.php';
  186 + $sendAPI = new \synQuery($code,$company);
  187 + $return = $sendAPI->query();
  188 + return $return;
  189 +}
  190 +
  191 +function wpjam_array_push($array, $data=null, $key=false){
  192 + $data = (array)$data;
  193 + $offset = ($key===false)?false:array_search($key, array_keys($array));
  194 + $offset = ($offset)?$offset:false;
  195 + if($offset){
  196 + return array_merge(
  197 + array_slice($array, 0, $offset),
  198 + $data,
  199 + array_slice($array, $offset)
  200 + );
  201 + }else{ // 没指定 $key 或者找不到,就直接加到末尾
  202 + return array_merge($array, $data);
  203 + }
176 } 204 }
1 -<?php  
2 -  
3 -namespace app\api\controller;  
4 -  
5 -use app\common\controller\Api;  
6 -  
7 -/**  
8 - * 首页接口  
9 - */  
10 -class Index extends Api  
11 -{  
12 - protected $noNeedLogin = ['*'];  
13 - protected $noNeedRight = ['*'];  
14 -  
15 - /**  
16 - * 首页  
17 - *  
18 - */  
19 - public function index()  
20 - {  
21 - $this->success('请求成功');  
22 - }  
23 -}  
@@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
2 2
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
  5 +use app\api\model\OrderDetail;
  6 +use app\api\model\OrderInfo;
  7 +use app\api\model\Order;
5 use app\api\model\UserAddress; 8 use app\api\model\UserAddress;
6 use app\api\model\UserMoneyLog; 9 use app\api\model\UserMoneyLog;
7 use app\api\model\UserScoreLog; 10 use app\api\model\UserScoreLog;
@@ -18,6 +21,7 @@ use think\Validate; @@ -18,6 +21,7 @@ use think\Validate;
18 class Member extends Api 21 class Member extends Api
19 { 22 {
20 protected $userModel; 23 protected $userModel;
  24 +
21 public function _initialize() 25 public function _initialize()
22 { 26 {
23 parent::_initialize(); 27 parent::_initialize();
@@ -49,7 +53,7 @@ class Member extends Api @@ -49,7 +53,7 @@ class Member extends Api
49 { 53 {
50 $userId = $this->getUserId(); 54 $userId = $this->getUserId();
51 55
52 - $userInfo = $this->userModel->where('id',$userId)->field('id,nickname,avatar,type,money,score')->find(); 56 + $userInfo = $this->userModel->where('id', $userId)->field('id,nickname,avatar,type,money,score')->find();
53 57
54 $this->success('SUCCESS', $userInfo); 58 $this->success('SUCCESS', $userInfo);
55 } 59 }
@@ -92,7 +96,7 @@ class Member extends Api @@ -92,7 +96,7 @@ class Member extends Api
92 $where['user_id'] = $userId; 96 $where['user_id'] = $userId;
93 $where['status'] = $status; 97 $where['status'] = $status;
94 98
95 - $data = $model->selectPageData($where,$page,$limit); 99 + $data = $model->selectPageData($where, $page, $limit);
96 100
97 $this->success('SUCCESS', $data); 101 $this->success('SUCCESS', $data);
98 } 102 }
@@ -123,7 +127,7 @@ class Member extends Api @@ -123,7 +127,7 @@ class Member extends Api
123 127
124 $where['pid'] = $userId; 128 $where['pid'] = $userId;
125 129
126 - $data = $this->userModel->selectPageData($where,$page,$limit); 130 + $data = $this->userModel->selectPageData($where, $page, $limit);
127 131
128 $this->success('SUCCESS', $data); 132 $this->success('SUCCESS', $data);
129 } 133 }
@@ -156,17 +160,17 @@ class Member extends Api @@ -156,17 +160,17 @@ class Member extends Api
156 160
157 $limit = Config::get('paginate.index_rows'); 161 $limit = Config::get('paginate.index_rows');
158 162
159 - $betweenTime = ['1970-1-1',date('Y-m-d')];  
160 - if ($date){  
161 - $dateArr = explode('-',$date); 163 + $betweenTime = ['1970-1-1', date('Y-m-d')];
  164 + if ($date) {
  165 + $dateArr = explode('-', $date);
162 $lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]); 166 $lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]);
163 - $lastDate = $dateArr[0].'-'.$dateArr[1].'-'.$lastDay;  
164 - $betweenTime = [$date,$lastDate]; 167 + $lastDate = $dateArr[0] . '-' . $dateArr[1] . '-' . $lastDay;
  168 + $betweenTime = [$date, $lastDate];
165 } 169 }
166 170
167 $where['user_id'] = $userId; 171 $where['user_id'] = $userId;
168 172
169 - $data = $model->selectPageData($where,$page,$limit,$betweenTime); 173 + $data = $model->selectPageData($where, $page, $limit, $betweenTime);
170 174
171 $this->success('SUCCESS', $data); 175 $this->success('SUCCESS', $data);
172 } 176 }
@@ -203,17 +207,96 @@ class Member extends Api @@ -203,17 +207,96 @@ class Member extends Api
203 $page = $this->request->param('page'); 207 $page = $this->request->param('page');
204 $date = $this->request->param('date'); 208 $date = $this->request->param('date');
205 $limit = Config::get('paginate.index_rows'); 209 $limit = Config::get('paginate.index_rows');
206 - $betweenTime = ['1970-1-1',date('Y-m-d')];  
207 - if ($date){  
208 - $dateArr = explode('-',$date); 210 + $betweenTime = ['1970-1-1', date('Y-m-d')];
  211 + if ($date) {
  212 + $dateArr = explode('-', $date);
209 $lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]); 213 $lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]);
210 - $lastDate = $dateArr[0].'-'.$dateArr[1].'-'.$lastDay;  
211 - $betweenTime = [$date,$lastDate]; 214 + $lastDate = $dateArr[0] . '-' . $dateArr[1] . '-' . $lastDay;
  215 + $betweenTime = [$date, $lastDate];
212 } 216 }
213 217
214 $where['user_id'] = $userId; 218 $where['user_id'] = $userId;
215 - $data = $model->selectPageData($where,$page,$limit,$betweenTime); 219 + $data = $model->selectPageData($where, $page, $limit, $betweenTime);
  220 +
  221 + $this->success('SUCCESS', $data);
  222 + }
216 223
  224 + /**
  225 + * @ApiTitle (我的订单)
  226 + * @ApiSummary (我的订单)
  227 + * @ApiMethod (POST)
  228 + * @ApiRoute (/api/member/getOrder)
  229 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  230 + * @ApiParams (name=type, type=string, required=true, description="1=我的订单2=我的团单")
  231 + * @ApiParams (name=page, type=string, required=true, description="页数")
  232 + * @ApiReturn({
  233 + "code": 1,
  234 + "msg": "SUCCESS",
  235 + "time": "1587560895",
  236 + "data": {
  237 + "total": 1,
  238 + "list": [
  239 + {
  240 + "score": "10.00", 变更积分
  241 + "after": "10.00", 变更后积分
  242 + "type": "type",
  243 + "createtime": "2020-04-20 16:13"
  244 + }
  245 + ]
  246 + }
  247 + })
  248 + */
  249 + public function getOrder()
  250 + {
  251 + $orderInfoModel = new OrderInfo();
  252 + $orderDetailModel = new OrderDetail();
  253 + $orderModel = new Order();
  254 + $userId = $this->getUserId();
  255 + $type = $this->request->param('type');
  256 + $page = $this->request->param('page');
  257 + $limit = Config::get('paginate.index_rows');
  258 + if (empty($type)) $this->error('缺少参数 type!');
  259 + $where = ['user_id'=>$userId];
  260 + if ($type == 1) $where['type'] = ['neq',3];
  261 + else $where['type'] = ['eq',3];
  262 + $list = $orderModel->selectPageData($where, $page, $limit);
  263 + $data = [];
  264 + foreach ($list['list'] as $k => $order) {
  265 + if ($order['status'] == -1){
  266 + $order['status_text'] = '已取消';
  267 + $order['goods_image'] = $orderInfoModel->where('order_id',$order['order_id'])->column('goods_image');
  268 + $data[] = $order;
  269 + }elseif($order['status'] == 1){
  270 + $order['status_text'] = '待付款';
  271 + if ($order['type'] == 3 && $order['team_group_status'] == 3) $order['status_text'] = '拼团失败';
  272 + $order['goods_image'] = $orderInfoModel->where('order_id',$order['order_id'])->column('goods_image');
  273 + $data[] = $order;
  274 + }elseif($order['status'] == 2){
  275 + $detailInfo = $orderDetailModel->where('order_id',$order['order_id'])->field('id,status')->select();
  276 + foreach ($detailInfo as $key => $detail){
  277 + $tmp['order_id'] = $order['order_id'];
  278 + $tmp['order_detail_id'] = $detail['id'];
  279 + $tmp['team_group_id'] = $order['team_group_id'];
  280 + $tmp['order_num'] = $order['order_num'];
  281 + $tmp['createtime'] = $order['createtime'];
  282 + $tmp['pay_total'] = 0;
  283 + $tmp['status'] = $detail['status'];
  284 + $tmp['status_text'] = $detail['status_text'];
  285 + $tmp['goods_image'] = [];
  286 + if ($order['type'] == 3 && $order['team_group_status'] == 1) $tmp['status_text'] = '待成团';
  287 + $orderInfo = $orderInfoModel->where(['order_detail_id'=>$detail['id']])->field('goods_image,goods_total')->select();
  288 + foreach ($orderInfo as $kk => $info){
  289 + $tmp['pay_total'] += $orderInfo[$kk]['goods_total'];
  290 + $tmp['goods_image'][] = $orderInfo[$kk]['goods_image'];
  291 + }
  292 + $data[] = $tmp;
  293 + }
  294 + }elseif($order['status'] == 3){
  295 + $order['status_text'] = '已退款';
  296 + $order['goods_image'] = $orderInfoModel->where('order_id',$order['order_id'])->column('goods_image');
  297 + $data[] = $order;
  298 + }
  299 + }
217 $this->success('SUCCESS', $data); 300 $this->success('SUCCESS', $data);
218 } 301 }
219 } 302 }
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
  5 +use addons\kdniao\library\Kdniao;
  6 +use app\api\model\OrderDetail;
5 use app\api\model\UserScoreLog; 7 use app\api\model\UserScoreLog;
6 use app\common\controller\Api; 8 use app\common\controller\Api;
7 use think\Db; 9 use think\Db;
@@ -22,6 +24,7 @@ class Order extends Api @@ -22,6 +24,7 @@ class Order extends Api
22 protected $orderAddressModel; 24 protected $orderAddressModel;
23 protected $orderAddressInvoiceModel; 25 protected $orderAddressInvoiceModel;
24 protected $orderInfoModel; 26 protected $orderInfoModel;
  27 + protected $orderDetailModel;
25 protected $userModel; 28 protected $userModel;
26 29
27 protected function _initialize() 30 protected function _initialize()
@@ -37,6 +40,7 @@ class Order extends Api @@ -37,6 +40,7 @@ class Order extends Api
37 $this->orderAddressModel = new \app\api\model\OrderAddress(); 40 $this->orderAddressModel = new \app\api\model\OrderAddress();
38 $this->orderAddressInvoiceModel = new \app\api\model\OrderAddressInvoice(); 41 $this->orderAddressInvoiceModel = new \app\api\model\OrderAddressInvoice();
39 $this->orderInfoModel = new \app\api\model\OrderInfo(); 42 $this->orderInfoModel = new \app\api\model\OrderInfo();
  43 + $this->orderDetailModel = new \app\api\model\OrderDetail();
40 $this->userModel = new \app\api\model\User(); 44 $this->userModel = new \app\api\model\User();
41 } 45 }
42 46
@@ -278,14 +282,12 @@ class Order extends Api @@ -278,14 +282,12 @@ class Order extends Api
278 //获取普通商品状态 282 //获取普通商品状态
279 if ($goodsIds) { 283 if ($goodsIds) {
280 $goodsList = $this->goodsModel->selectGoodsStatus(['id' => ['in', $goodsIds]]); 284 $goodsList = $this->goodsModel->selectGoodsStatus(['id' => ['in', $goodsIds]]);
281 -  
282 //判断商品是否有库存和状态 285 //判断商品是否有库存和状态
283 foreach ($goodsList as $k => $v) { 286 foreach ($goodsList as $k => $v) {
284 if ($v['status'] == 2) $this->error($v['ch_name'] . '商品已下架'); 287 if ($v['status'] == 2) $this->error($v['ch_name'] . '商品已下架');
285 if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足'); 288 if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
286 } 289 }
287 } 290 }
288 -  
289 //获取积分商品状态 291 //获取积分商品状态
290 if ($goodsIntegralIds) { 292 if ($goodsIntegralIds) {
291 $goodsIntegralList = $this->integralGoodsModel->selectGoodsStatus(['id' => ['in', $goodsIntegralIds]]); 293 $goodsIntegralList = $this->integralGoodsModel->selectGoodsStatus(['id' => ['in', $goodsIntegralIds]]);
@@ -1272,4 +1274,145 @@ class Order extends Api @@ -1272,4 +1274,145 @@ class Order extends Api
1272 if ($res) $this->success('取消订单成功'); 1274 if ($res) $this->success('取消订单成功');
1273 else $this->error('取消订单失败'); 1275 else $this->error('取消订单失败');
1274 } 1276 }
  1277 +
  1278 + /**
  1279 + * @ApiTitle (订单详情)
  1280 + * @ApiSummary (订单详情)
  1281 + * @ApiMethod (POST)
  1282 + * @ApiRoute (/api/order/orderInfo)
  1283 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  1284 + * @ApiParams (name=order_id, type=string, required=true, description="订单id")
  1285 + * @ApiParams (name=order_detail_id, type=string, required=false, description="订单子表id")
  1286 + * @ApiReturn ({
  1287 + {
  1288 + "code": 1,
  1289 + "msg": "success",
  1290 + "time": "1588041622",
  1291 + "data": {
  1292 + "createtime": "2020-04-27 16:56:31", 下单时间
  1293 + "order_num": "2020042710254102", 订单号
  1294 + "status": "2",
  1295 + "postage_date": "", 配送日期
  1296 + "postage_time": "", 配送时间
  1297 + "pay_type": "2", 支付类型
  1298 + "pay_total": "55.65", 支付金额
  1299 + "goods_total": "27.00", 商品金额
  1300 + "postage_total": "30.00", 运费
  1301 + "discount_price": "1.35", 折扣金额
  1302 + "score": "", 积分
  1303 + "ticket_price": "0.00", 优惠券金额
  1304 + "ticketcode_id": 0,
  1305 + "ticketcode": 0, 优惠码
  1306 + "name": "", 收货人姓名
  1307 + "mobile": "13752011792", 收货人手机号
  1308 + "address": 123, 收货详情地址
  1309 + "ch_province_name": "天津", 收货地址省
  1310 + "ch_city_name": "天津市", 收货地址市
  1311 + "ch_county_name": "和平区", 收货地址县
  1312 + "status_text": "已完成" 订单状态
  1313 + }
  1314 + }
  1315 + })
  1316 + */
  1317 + public function orderInfo()
  1318 + {
  1319 + $userId = $this->getUserId();
  1320 + $param = $this->request->param();
  1321 + $rule = [
  1322 + 'order_id' => 'require',
  1323 + ];
  1324 +
  1325 + $msg = [
  1326 + 'order_id' => '缺少参数 order_id!',
  1327 + ];
  1328 +
  1329 + $validate = new Validate($rule, $msg);
  1330 + $result = $validate->check($param);
  1331 + if (!$result) {
  1332 + $this->error(__($validate->getError()));
  1333 + }
  1334 +
  1335 + $order = $this->orderModel->getInfo(['o.id' => $param['order_id']]);
  1336 + if (!$order) $this->error('订单不存在');
  1337 +
  1338 +
  1339 + if (!empty($order['ticketcode_id'])) {
  1340 + $order['ticketcode'] = $this->ticketCodeModel->where('id', $order['ticketcode_id'])->value('code');
  1341 + }
  1342 + $detailInfo = $this->orderDetailModel->where('id',$param['order_detail_id'])->field('shipper_code,logistic_code,status')->find();
  1343 + if (!empty($order['team_group_status'] && $order['team_group_status'] == 1)) {
  1344 + $order['status_text'] = '待成团';
  1345 + } elseif (!empty($order['team_group_status'] && $order['team_group_status'] == 2 && $detailInfo['status'] == 2)) {
  1346 + $order['status_text'] = '待发货';
  1347 + } elseif (!empty($order['team_group_status'] && $order['team_group_status'] == 3)) {
  1348 + $order['status_text'] = '拼团失败';
  1349 + } elseif ($order['status'] == 2) {
  1350 + $order['status_text'] = $this->orderDetailModel->where('order_id', $param['order_id'])->field('status')->find()['status_text'];
  1351 + } elseif ($order['status'] == 1) {
  1352 + $order['status_text'] = '待付款';
  1353 + }elseif ($order['status'] == 3) {
  1354 + $order['status_text'] = '已退款';
  1355 + $order['refund_time'] = '2020-01-01 08:33:23';
  1356 + $order['refund_remark'] = '退款至微信钱包';
  1357 + $order['refund_price'] = '8888';
  1358 +
  1359 + }
  1360 +
  1361 + if($detailInfo['status'] == 3 || $detailInfo['status'] == 4 || $detailInfo['status'] == 5){
  1362 + if (empty($detailInfo['shipper_code']) || empty($detailInfo['logistic_code'])) {
  1363 + $this->error('该订单缺少物流单号或者快递公司编码参数');
  1364 + }
  1365 + $code = $detailInfo['shipper_code'];
  1366 + $company = $detailInfo['logistic_code'];
  1367 + $kdniao = new Kdniao();
  1368 +
  1369 + $wuliu = $kdniao->getOrderTracesByJson($company, $code);
  1370 + $wuliu = json_decode($wuliu, true);
  1371 + $wuliu = isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : ['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())];
  1372 + if (!empty($wuliu[0])){
  1373 + $order['wuliu'] = $wuliu[0];
  1374 + }else{
  1375 + $order['wuliu'] = $wuliu;
  1376 + }
  1377 + }
  1378 +
  1379 + $this->success('success', $order);
  1380 + }
  1381 +
  1382 + /**
  1383 + * @ApiTitle (订单物流详情)
  1384 + * @ApiSummary (订单物流详情)
  1385 + * @ApiMethod (POST)
  1386 + * @ApiRoute (/api/order/orderLogisticsInfo)
  1387 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  1388 + * @ApiParams (name=order_detail_id, type=string, required=true, description="订单子表id")
  1389 + * @ApiReturn ({
  1390 + })
  1391 + */
  1392 + public function orderLogisticsInfo()
  1393 + {
  1394 + $user_id = $this->getUserId();
  1395 + $order_detail_id = $this->request->param('order_detail_id');
  1396 + $orderDetailModel = new OrderDetail();
  1397 + $where['user_id'] = ['eq', $user_id];
  1398 + $where['id'] = ['eq', $order_detail_id];
  1399 + $data = $orderDetailModel->where($where)->field('shipper_code,logistic_code')->find();
  1400 + if (empty($data)) {
  1401 + $this->error('查询为空');
  1402 + }
  1403 +
  1404 + if (empty($data['shipper_code']) || empty($data['logistic_code'])) {
  1405 + $this->error('该订单缺少物流单号或者快递公司编码参数');
  1406 + }
  1407 + $code = $data['shipper_code'];
  1408 + $company = $data['logistic_code'];
  1409 + $kdniao = new Kdniao();
  1410 +
  1411 + $wuliu = $kdniao->getOrderTracesByJson($company, $code);
  1412 + $wuliu = json_decode($wuliu, true);
  1413 + $wuliu = isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]];
  1414 + $data['company_name'] = Db::name('kdniao')->where(['code' => $data['logistic_code']])->value('company');
  1415 + $data['wuliu'] = $wuliu;
  1416 + $this->success('SUCCESS', $data);
  1417 + }
1275 } 1418 }
@@ -22,6 +22,7 @@ class Sundry extends Api @@ -22,6 +22,7 @@ class Sundry extends Api
22 parent::_initialize(); 22 parent::_initialize();
23 23
24 } 24 }
  25 +
25 /** 26 /**
26 * @ApiTitle (幻灯片) 27 * @ApiTitle (幻灯片)
27 * @ApiSummary (幻灯片) 28 * @ApiSummary (幻灯片)
@@ -39,10 +40,11 @@ class Sundry extends Api @@ -39,10 +40,11 @@ class Sundry extends Api
39 }, 40 },
40 }) 41 })
41 */ 42 */
42 - public function getSlide(){ 43 + public function getSlide()
  44 + {
43 $slideModel = new Slide(); 45 $slideModel = new Slide();
44 $data = $slideModel->selectData([]); 46 $data = $slideModel->selectData([]);
45 - $this->success('SUCCESS',$data); 47 + $this->success('SUCCESS', $data);
46 } 48 }
47 49
48 /** 50 /**
@@ -64,12 +66,13 @@ class Sundry extends Api @@ -64,12 +66,13 @@ class Sundry extends Api
64 }, 66 },
65 }) 67 })
66 */ 68 */
67 - public function getUserKeyword(){  
68 - $limit = $this->request->param('limit')?$this->request->param('limit'):8; 69 + public function getUserKeyword()
  70 + {
  71 + $limit = $this->request->param('limit') ? $this->request->param('limit') : 8;
69 $model = new KeywordLog(); 72 $model = new KeywordLog();
70 $userId = $this->getUserId(); 73 $userId = $this->getUserId();
71 - $data = $model->selectData(['user_id'=>$userId],$limit);  
72 - $this->success('SUCCESS',$data); 74 + $data = $model->selectData(['user_id' => $userId], $limit);
  75 + $this->success('SUCCESS', $data);
73 } 76 }
74 77
75 /** 78 /**
@@ -90,7 +93,8 @@ class Sundry extends Api @@ -90,7 +93,8 @@ class Sundry extends Api
90 }, 93 },
91 }) 94 })
92 */ 95 */
93 - public function getArea(){ 96 + public function getArea()
  97 + {
94 $areaModel = new Area(); 98 $areaModel = new Area();
95 $params = $this->request->param(); 99 $params = $this->request->param();
96 $where['pid'] = 0; 100 $where['pid'] = 0;
@@ -99,7 +103,7 @@ class Sundry extends Api @@ -99,7 +103,7 @@ class Sundry extends Api
99 103
100 $data = $areaModel->where($where)->field('id,name')->select(); 104 $data = $areaModel->where($where)->field('id,name')->select();
101 105
102 - $this->success('SUCCESS',$data); 106 + $this->success('SUCCESS', $data);
103 } 107 }
104 108
105 /** 109 /**
@@ -121,7 +125,8 @@ class Sundry extends Api @@ -121,7 +125,8 @@ class Sundry extends Api
121 }, 125 },
122 }) 126 })
123 */ 127 */
124 - public function getDeliveryTime(){ 128 + public function getDeliveryTime()
  129 + {
125 $model = new AreaExtend(); 130 $model = new AreaExtend();
126 $params = $this->request->param(); 131 $params = $this->request->param();
127 132
@@ -131,10 +136,10 @@ class Sundry extends Api @@ -131,10 +136,10 @@ class Sundry extends Api
131 if (!empty($params['county_id'])) $where['county_id'] = $params['county_id']; 136 if (!empty($params['county_id'])) $where['county_id'] = $params['county_id'];
132 137
133 $data = $model->where($where)->field('is_special,starttime1,endtime1,starttime2,endtime2')->find(); 138 $data = $model->where($where)->field('is_special,starttime1,endtime1,starttime2,endtime2')->find();
134 - $startDate = date("Y-m-d",strtotime('+'.$data['starttime1'].' days',time()));  
135 - $endDate = date("Y-m-d",strtotime('+'.$data['endtime1'].' days',time()));  
136 - $data['date'] = period_date($startDate,$endDate);  
137 - $this->success('SUCCESS',$data); 139 + $startDate = date("Y-m-d", strtotime('+' . $data['starttime1'] . ' days', time()));
  140 + $endDate = date("Y-m-d", strtotime('+' . $data['endtime1'] . ' days', time()));
  141 + $data['date'] = period_date($startDate, $endDate);
  142 + $this->success('SUCCESS', $data);
138 } 143 }
139 144
140 /** 145 /**
@@ -154,14 +159,49 @@ class Sundry extends Api @@ -154,14 +159,49 @@ class Sundry extends Api
154 }, 159 },
155 }) 160 })
156 */ 161 */
157 - public function getDeliveryFastTime(){ 162 + public function getDeliveryFastTime()
  163 + {
158 $model = new WeekTemplate(); 164 $model = new WeekTemplate();
159 $week = $this->request->param('week'); 165 $week = $this->request->param('week');
160 if (empty($week)) $this->error('缺少参数 week!'); 166 if (empty($week)) $this->error('缺少参数 week!');
161 - $data = $model->selectData(['type'=>$week]);  
162 - foreach ($data as $k=>$v){  
163 - $data[$k] = $v['starttime'].'-'.$v['endtime']; 167 + $data = $model->selectData(['type' => $week]);
  168 + foreach ($data as $k => $v) {
  169 + $data[$k] = $v['starttime'] . '-' . $v['endtime'];
  170 + }
  171 + $this->success('SUCCESS', $data);
  172 + }
  173 +
  174 + /**
  175 + * @ApiTitle (获取文本)
  176 + * @ApiSummary (获取文本)
  177 + * @ApiMethod (POST)
  178 + * @ApiRoute (/api/sundry/getText)
  179 + * @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
  180 + * @ApiParams (name=type, type=string, required=true, description="类型:1=会员特权文本,2=提现说明文本,3=配送详情文本")
  181 + * @ApiReturn({
  182 + "code": 1,
  183 + "msg": "SUCCESS",
  184 + "time": "1553839125",
  185 + "data": {
  186 + "id": "id",// 地区id
  187 + "name": "name",// 名称
  188 + },
  189 + })
  190 + */
  191 + public function getText()
  192 + {
  193 + $type = $this->request->param('type');
  194 + switch ($type) {
  195 + case 1:
  196 + $data = '会员特权文本';
  197 + break;
  198 + case 2:
  199 + $data = '提现说明文本';
  200 + break;
  201 + case 3:
  202 + $data = '配送详情文本';
  203 + break;
164 } 204 }
165 - $this->success('SUCCESS',$data); 205 + $this->success('SUCCESS', $data);
166 } 206 }
167 } 207 }
@@ -15,6 +15,36 @@ class Order extends Model @@ -15,6 +15,36 @@ class Order extends Model
15 protected $createTime = 'createtime'; 15 protected $createTime = 'createtime';
16 protected $updateTime = 'updatetime'; 16 protected $updateTime = 'updatetime';
17 17
  18 +
  19 + public function getCreatetimeAttr($value)
  20 + {
  21 + return date('Y-m-d H:i:s',$value);
  22 + }
  23 + public function selectPageData($where,$page,$limit)
  24 + {
  25 + $total = $this
  26 + ->where($where)
  27 + ->count();
  28 +
  29 + $orderList = $this
  30 + ->where($where)
  31 + ->field('id order_id,order_num,createtime,pay_total,status,type,team_group_status,team_group_id')
  32 + ->order('createtime desc')
  33 + ->page($page,$limit)
  34 + ->select();
  35 +
  36 + return ['total' => $total, 'list' => $orderList];
  37 + }
  38 +
  39 + public function getInfo($where)
  40 + {
  41 + $data = $this->alias('o')
  42 + ->join('fa_order_address oa', 'oa.order_id=o.id')
  43 + ->where($where)
  44 + ->field('o.createtime,o.order_num,o.status,o.postage_date,o.postage_time,o.pay_type,o.pay_total,o.goods_total,o.postage_total,o.discount_price,o.score,o.team_group_status,o.ticket_price,o.ticketcode_id,oa.name,oa.mobile,oa.address,oa.ch_province_name,oa.ch_city_name,oa.ch_county_name')
  45 + ->find();
  46 + return $data;
  47 + }
18 /** 48 /**
19 * 余额支付 49 * 余额支付
20 * @param $order_id 订单id 50 * @param $order_id 订单id
@@ -49,6 +79,7 @@ class Order extends Model @@ -49,6 +79,7 @@ class Order extends Model
49 //获取以仓库分好的商品 79 //获取以仓库分好的商品
50 $goodsDepotList = setArr($data); 80 $goodsDepotList = setArr($data);
51 $orderInfoData = []; 81 $orderInfoData = [];
  82 + $oldOrderInfoIds = []; //获取创建订单时 order_info_id
52 foreach ($goodsDepotList as $k => $goodsDepot) { 83 foreach ($goodsDepotList as $k => $goodsDepot) {
53 $detailArr = reset($goodsDepot); 84 $detailArr = reset($goodsDepot);
54 $detailData = [ 85 $detailData = [
@@ -62,8 +93,6 @@ class Order extends Model @@ -62,8 +93,6 @@ class Order extends Model
62 ]; 93 ];
63 //添加订单子表 94 //添加订单子表
64 $detailId = $orderDetailModel->insertGetId($detailData); 95 $detailId = $orderDetailModel->insertGetId($detailData);
65 - $oldOrderInfoIds = []; //获取创建订单时 order_info_id  
66 -  
67 foreach ($goodsDepot as $key => $goodsDepotInfo) { 96 foreach ($goodsDepot as $key => $goodsDepotInfo) {
68 $where = [ 97 $where = [
69 'order_id' => $order_id, 98 'order_id' => $order_id,
@@ -72,7 +101,7 @@ class Order extends Model @@ -72,7 +101,7 @@ class Order extends Model
72 'type' => $order['type'] == 3 ? 3 : $goodsDepotInfo['type'], 101 'type' => $order['type'] == 3 ? 3 : $goodsDepotInfo['type'],
73 ]; 102 ];
74 $orderInfo = $orderInfoModel->where($where)->find(); 103 $orderInfo = $orderInfoModel->where($where)->find();
75 - $oldOrderInfoIds[] = $orderInfo['id']; 104 + if (!in_array($orderInfo['id'],$oldOrderInfoIds)) $oldOrderInfoIds[] = $orderInfo['id'];
76 $orderInfoData[] = [ 105 $orderInfoData[] = [
77 'pay_type' => $orderInfo['pay_type'], //余额支付 106 'pay_type' => $orderInfo['pay_type'], //余额支付
78 'order_id' => $order_id, 107 'order_id' => $order_id,
@@ -177,6 +206,158 @@ class Order extends Model @@ -177,6 +206,158 @@ class Order extends Model
177 } 206 }
178 } 207 }
179 208
  209 + /**
  210 + * 微信支付回调
  211 + * @param $order_id 订单id
  212 + * @param $user_id 用户id
  213 + * @param $money 支付金额
  214 + * @return boolean
  215 + */
  216 + public function WXPay($order_id, $user_id, $money, $goodsList)
  217 + {
  218 + $goodsModel = new \app\api\model\Goods();
  219 + $userScoreLogModel = new \app\api\model\UserScoreLog();
  220 + $orderDetailModel = new \app\api\model\OrderDetail();
  221 + $orderInfoModel = new \app\api\model\OrderInfo();
  222 + Db::startTrans();
  223 + try {
  224 + $areaId = Db::name('order_address')->where('order_id', $order_id)->value('province_id');
  225 + $oldscore = Db::name('user')->where('id', $user_id)->value('score');
  226 + $integral_total = 0; //购买商品所需积分
  227 + //获取订单
  228 + $order = $this->where('id', $order_id)->field('id,pay_total,postage_total,ticket_price,ticketcode_price,type,team_group_id,team_group_status')->find();
  229 +
  230 + foreach ($goodsList as $key => $goods) {
  231 + $integral_total += $goods['score']; //累计积分总数
  232 + if ($goods['type'] == 3) $goods['type'] = '1';
  233 + //根据仓库进行拆单
  234 + $data[] = $goodsModel->getDepot($goods['goods_id'], $areaId, $goods['number'], $goods['type']);
  235 + if (!$data[$key]) return ['code' => -1, 'msg' => $goods['ch_goods_name'] . ' 库存不足'];
  236 + }
  237 + //获取以仓库分好的商品
  238 + $goodsDepotList = setArr($data);
  239 + $orderInfoData = [];
  240 + $oldOrderInfoIds = []; //获取创建订单时 order_info_id
  241 + foreach ($goodsDepotList as $k => $goodsDepot) {
  242 + $detailArr = reset($goodsDepot);
  243 + $detailData = [
  244 + 'order_id' => $order_id,
  245 + 'user_id' => $user_id,
  246 + 'pay_type' => 2, //余额支付
  247 + 'depot_id' => $detailArr['depots_id'],
  248 + 'status' => 2, //代发货
  249 + 'createtime' => time(),
  250 + 'updatetime' => time(),
  251 + ];
  252 + //添加订单子表
  253 + $detailId = $orderDetailModel->insertGetId($detailData);
  254 + foreach ($goodsDepot as $key => $goodsDepotInfo) {
  255 + $where = [
  256 + 'order_id' => $order_id,
  257 + 'user_id' => $user_id,
  258 + 'goods_id' => $goodsDepotInfo['goods_id'],
  259 + 'type' => $order['type'] == 3 ? 3 : $goodsDepotInfo['type'],
  260 + ];
  261 + $orderInfo = $orderInfoModel->where($where)->find();
  262 + if (!in_array($orderInfo['id'],$oldOrderInfoIds)) $oldOrderInfoIds[] = $orderInfo['id'];
  263 + $orderInfoData[] = [
  264 + 'pay_type' => $orderInfo['pay_type'], //余额支付
  265 + 'order_id' => $order_id,
  266 + 'order_detail_id' => $detailId,
  267 + 'user_id' => $user_id,
  268 + 'goods_id' => $goodsDepotInfo['goods_id'],
  269 + 'type' => $goodsDepotInfo['type'],
  270 + 'ch_goods_name' => $orderInfo['ch_goods_name'],
  271 + 'en_goods_name' => $orderInfo['en_goods_name'],
  272 + 'goods_image' => $orderInfo['goods_image'],
  273 + 'number' => $goodsDepotInfo['number'],
  274 + 'goods_total' => round($orderInfo['goods_total'] / $orderInfo['number'] * $goodsDepotInfo['number'], 2),
  275 + 'pay_total' => $orderInfo['pay_total'],
  276 + 'postage_total' => $orderInfo['postage_total'],
  277 + 'score' => $orderInfo['score'] / $orderInfo['number'] * $goodsDepotInfo['number'],
  278 + ];
  279 +
  280 + //减仓库库存
  281 + Db::name('depot')->where('id', $goodsDepotInfo['depots_id'])->setDec('stock_num', $goodsDepotInfo['number']);
  282 + //判断商品类型减去库存 加销量
  283 + if ($goodsDepotInfo['type'] == 2) {
  284 + Db::name('integral_goods')->where('id', $goodsDepotInfo['goods_id'])->setDec('stock_num', $goodsDepotInfo['number']);
  285 + Db::name('integral_goods')->where('id', $goodsDepotInfo['goods_id'])->setInc('sales_actual', $goodsDepotInfo['number']);
  286 + } else {
  287 + Db::name('goods')->where('id', $goodsDepotInfo['goods_id'])->setDec('stock_num', $goodsDepotInfo['number']);
  288 + Db::name('goods')->where('id', $goodsDepotInfo['goods_id'])->setInc('sales_actual', $goodsDepotInfo['number']);
  289 + }
  290 + }
  291 + }
  292 + //添加订单详情
  293 + $orderInfoModel->saveAll($orderInfoData);
  294 + //删除之前订单详情
  295 + $orderInfoModel->where(['id' => ['in', $oldOrderInfoIds]])->delete();
  296 +
  297 + //有积分商品减积分
  298 + if ($integral_total != 0) {
  299 + $userScoreLogModel->setDecScore($user_id, $integral_total);
  300 + }
  301 + //将订单状态修改为已支付
  302 + $this->where('id', $order_id)->update(['status' => 2, 'paytime' => time()]);
  303 + //积分变动表记录
  304 + $oldscore = Db::name('user')->where('id', $user_id)->value('score');
  305 + $scoredata = [
  306 + 'user_id' => $user_id,
  307 + 'type' => 1, //购物返积分
  308 + 'score' => intval($money),
  309 + 'before' => $oldscore,
  310 + 'after' => $oldscore + intval($money),
  311 + 'createtime' => time(),
  312 + ];
  313 + Db::name('user_score_log')->insert($scoredata);
  314 + Db::name('user')->where('id', $user_id)->setInc('score', intval($money));
  315 +
  316 +
  317 + $user_pid = Db::name('user')->where('id', $user_id)->value('pid');
  318 + //判断是否有上级进行返利 团购订单不在这里返利
  319 + if ($user_pid && $order['type'] != 3) {
  320 + if (!empty($order['ticket_price'])) $order['pay_total'] += $order['ticket_price'];
  321 + if (!empty($order['ticketcode_price'])) $order['pay_total'] += $order['ticketcode_price'];
  322 + if (!empty($order['postage_total'])) $order['pay_total'] -= $order['postage_total'];
  323 + $parentInfo = Db::name('user')->where('id', $user_pid)->find();
  324 + //普通用户无返利
  325 + if ($parentInfo['type'] != 1) {
  326 + $rebateMoney = get_rebate($order['pay_total'], $parentInfo['type']);
  327 + $rebatedata = [
  328 + 'user_id' => $user_pid,
  329 + 'type' => 4, //佣金收入(返利)
  330 + 'money' => $rebateMoney,
  331 + 'before' => $parentInfo['money'],
  332 + 'after' => $parentInfo['money'] + $rebateMoney,
  333 + 'createtime' => time(),
  334 + ];
  335 + Db::name('user_money_log')->insert($rebatedata);
  336 + Db::name('user')->where('id', $user_pid)->setInc('money', $rebateMoney);
  337 + }
  338 + }
  339 + if ($order['type'] == 3 && !empty($order['team_group_id'])) {
  340 + //参团
  341 + $this->joinTeam($order, $user_id);
  342 + } elseif ($order['type'] == 3) {
  343 + //开团
  344 + $this->createTeam($order, $user_id);
  345 + }
  346 + Db::commit();
  347 + return true;
  348 +
  349 + } catch (Exception $e) {
  350 + Db::rollback();
  351 + return false;
  352 + }
  353 + }
  354 +
  355 + /**
  356 + * 开团
  357 + * @param $order
  358 + * @param $user_id
  359 + * @return bool
  360 + */
180 public function createTeam($order, $user_id) 361 public function createTeam($order, $user_id)
181 { 362 {
182 $goods_id = Db::name('order_info')->where(['order_id' => $order['id']])->value('goods_id'); 363 $goods_id = Db::name('order_info')->where(['order_id' => $order['id']])->value('goods_id');
@@ -237,6 +418,12 @@ class Order extends Model @@ -237,6 +418,12 @@ class Order extends Model
237 Db::name('team_group_info')->insertGetId($teamInfoData); 418 Db::name('team_group_info')->insertGetId($teamInfoData);
238 } 419 }
239 420
  421 + /**
  422 + * 参团
  423 + * @param $order
  424 + * @param $user_id
  425 + * @return bool
  426 + */
240 public function joinTeam($order, $user_id) 427 public function joinTeam($order, $user_id)
241 { 428 {
242 $user_info = Db::name('user')->where(['id' => $user_id])->field('id,avatar,nickname,pid')->find(); 429 $user_info = Db::name('user')->where(['id' => $user_id])->field('id,avatar,nickname,pid')->find();
@@ -292,8 +479,14 @@ class Order extends Model @@ -292,8 +479,14 @@ class Order extends Model
292 $this->where(['team_group_id' => $order['team_group_id'],'user_id'=>['not in',$ids]])->update(['team_group_status' => 3]); 479 $this->where(['team_group_id' => $order['team_group_id'],'user_id'=>['not in',$ids]])->update(['team_group_status' => 3]);
293 480
294 } 481 }
  482 + return true;
295 } 483 }
296 484
  485 + /**
  486 + * 取消订单
  487 + * @param $order
  488 + * @return bool
  489 + */
297 public function orderCancel($order){ 490 public function orderCancel($order){
298 $userTicketModel = new UserTicket(); 491 $userTicketModel = new UserTicket();
299 $ticketcodeModel = new Ticketcode(); 492 $ticketcodeModel = new Ticketcode();
@@ -315,4 +508,13 @@ class Order extends Model @@ -315,4 +508,13 @@ class Order extends Model
315 return false; 508 return false;
316 } 509 }
317 } 510 }
  511 +
  512 + /**
  513 + * 订单退款
  514 + * @param $order
  515 + */
  516 + public function orderRefund($order){
  517 + $this->where('id',$order['id'])->update(['status'=>4]);
  518 + }
  519 +
318 } 520 }
@@ -14,5 +14,21 @@ class OrderDetail extends Model @@ -14,5 +14,21 @@ class OrderDetail extends Model
14 protected $createTime = 'createtime'; 14 protected $createTime = 'createtime';
15 protected $updateTime = 'updatetime'; 15 protected $updateTime = 'updatetime';
16 16
  17 + // 追加属性
  18 + protected $append = [
  19 + 'status_text'
  20 + ];
17 21
  22 + public function getStatusList()
  23 + {
  24 + //状态:-1=已取消,1=待支付,2=待发货,3=待收货,4=待评价,5=已完成
  25 + return ['-1' => '已取消', '1' => '待支付', '2' => '待发货', '3' => '待收货', '4' => '待评价', '5' => '已完成'];
  26 + }
  27 +
  28 + public function getStatusTextAttr($value, $data)
  29 + {
  30 + $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  31 + $list = $this->getStatusList();
  32 + return isset($list[$value]) ? $list[$value] : '';
  33 + }
18 } 34 }
此 diff 太大无法显示。
1 define([], function () { 1 define([], function () {
2 - //修改上传的接口调用 2 + if ($('.kdniao').length > 0) {
  3 +
  4 + $('.kdniao').each(function () {
  5 + var code = $(this).data('code');
  6 +
  7 + $(this).addClass('btn btn-xs bg-success').append('<i class="fa fa-truck"></i>' + code);
  8 + });
  9 +
  10 + $('.kdniao').click(function () {
  11 + var company = $(this).data('company');
  12 + var code = $(this).data('code');
  13 +
  14 + if (company && code) {
  15 + Layer.open({
  16 + type: 2,
  17 + area: ['700px', '450px'],
  18 + fixed: false, //不固定
  19 + maxmin: true,
  20 + content: '/addons/kdniao/index/query?company=' + company + '&code=' + code
  21 + });
  22 + }
  23 + });
  24 +}
  25 +//修改上传的接口调用
3 require(['upload'], function (Upload) { 26 require(['upload'], function (Upload) {
4 var _onUploadResponse = Upload.events.onUploadResponse; 27 var _onUploadResponse = Upload.events.onUploadResponse;
5 Upload.events.onUploadResponse = function (response) { 28 Upload.events.onUploadResponse = function (response) {