作者 张佳

1

正在显示 49 个修改的文件 包含 4800 行增加0 行删除

要显示太多修改。

为保证性能只显示 49 of 49+ 个文件。

# sos
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
... ...
# 开发者文档
### 一、约束
---
1. 开发规范原则上按照ThinkPHP5.0完全开发手册中的标准。
1. 模块 common 中 web 目录内的 BaseModel 为基础共用的 model,不写入任何其他模块业务相关方法。
1. 在模块 common 中的模型中显式定义数据库名称。
1. 模块 web 中,是我们编写具体业务的模块。其中 model 目录先继承 common 中 model 目录下的 model 再写自己的逻辑。
1. 模块 web 中,控制器需要继承当前模块的 Controller,该 Controller 需要继承 common 模块中的 WebController。
1. 公共方法参考 common.php,该文件不要维护,如需添加内容,请与项目负责人联系。
1. 异常处理使用 application\common\exception\BaseException。
1. 返回数据必须使用$this->throwError、$this->renderJson、$this->renderSuccess、$this->renderError。参考 application\common\service\Render。
1. 不允许直接使用 Db 操作数据库(特殊需要请说明原因)。
1. 原则上在 Controller 不做数据库操作。
1. 所有类编写注释。
~~~
/**
* 类说明
*
* Class 类名称
* @package 位置(例如:app\sapi\controller)
*/
~~~
12. 任何方法都需要编写注释,说明参数已经方法的含义。
~~~
/**
* 方法说明
*
* @param 参数名 含义
* @return 返回类型(例如:array|bool|mixed)
* @throws 异常处理(例如:\think\exception\DbException)
*/
~~~
13. 任何变量、常量、对象等都需注释说明含义。
~~~
// 含义
/* @var 类型 名称 含义 */
~~~
14.原则上每行代码都需要注释清楚作用,也可同一功能一起加注释,如果逻辑性较强的区域需要注释开始、结束。
~~~
/*---------- 说明 start ----------*/
/*---------- 说明 end ----------*/
~~~
### 二、关于权限
---
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
return [];
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
use think\Request;
use think\Log;
/**
* 打印调试函数
* @param $content
* @param $is_die
*/
function pre($content, $is_die = true)
{
header('Content-type: text/html; charset=utf-8');
echo '<pre>' . print_r($content, true);
$is_die && die();
}
/**
* 驼峰命名转下划线命名
* @param $str
* @return string
*/
function toUnderScore($str)
{
$dstr = preg_replace_callback('/([A-Z]+)/', function ($matchs) {
return '_' . strtolower($matchs[0]);
}, $str);
return trim(preg_replace('/_{2,}/', '_', $dstr), '_');
}
/**
* 生成密码hash值
* @param $password
* @return string
*/
function api_hash($password)
{
return md5(md5($password) . 'api_salt_SmTRx');
}
/**
* 获取当前域名及根路径
* @return string
*/
function base_url()
{
static $baseUrl = '';
if (empty($baseUrl)) {
$request = Request::instance();
$subDir = str_replace('\\', '/', dirname($request->server('PHP_SELF')));
$baseUrl = $request->scheme() . '://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/');
}
return $baseUrl;
}
/**
* 写入日志 (使用tp自带驱动记录到runtime目录中)
* @param $value
* @param string $type
*/
function log_write($value, $type = 'api-info')
{
$msg = is_string($value) ? $value : var_export($value, true);
Log::record($msg, $type);
}
/**
* curl请求指定url (get)
* @param $url
* @param array $data
* @return mixed
*/
function curl($url, $data = [])
{
// 处理get数据
if (!empty($data)) {
$url = $url . '?' . http_build_query($data);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* curl请求指定url (post)
* @param $url
* @param array $data
* @return mixed
*/
function curlPost($url, $data = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 多维数组合并
* @param $array1
* @param $array2
* @return array
*/
function array_merge_multiple($array1, $array2)
{
$merge = $array1 + $array2;
$data = [];
foreach ($merge as $key => $val) {
if (
isset($array1[$key])
&& is_array($array1[$key])
&& isset($array2[$key])
&& is_array($array2[$key])
) {
$data[$key] = array_merge_multiple($array1[$key], $array2[$key]);
} else {
$data[$key] = isset($array2[$key]) ? $array2[$key] : $array1[$key];
}
}
return $data;
}
/**
* 二维数组排序
* @param $arr
* @param $keys
* @param bool $desc
* @return mixed
*/
function array_sort($arr, $keys, $desc = false)
{
$key_value = $new_array = array();
foreach ($arr as $k => $v) {
$key_value[$k] = $v[$keys];
}
if ($desc) {
arsort($key_value);
} else {
asort($key_value);
}
reset($key_value);
foreach ($key_value as $k => $v) {
$new_array[$k] = $arr[$k];
}
return $new_array;
}
/**
* 数据导出到excel(csv文件)
* @param $fileName
* @param array $tileArray
* @param array $dataArray
*/
function export_excel($fileName, $tileArray = [], $dataArray = [])
{
ini_set('memory_limit', '512M');
ini_set('max_execution_time', 0);
ob_end_clean();
ob_start();
header("Content-Type: text/csv");
header("Content-Disposition:filename=" . $fileName);
$fp = fopen('php://output', 'w');
fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));// 转码 防止乱码(比如微信昵称)
fputcsv($fp, $tileArray);
$index = 0;
foreach ($dataArray as $item) {
if ($index == 1000) {
$index = 0;
ob_flush();
flush();
}
$index++;
fputcsv($fp, $item);
}
ob_flush();
flush();
ob_end_clean();
}
/**
* 隐藏敏感字符
* @param $value
* @return string
*/
function substr_cut($value)
{
$strlen = mb_strlen($value, 'utf-8');
if ($strlen <= 1) return $value;
$firstStr = mb_substr($value, 0, 1, 'utf-8');
$lastStr = mb_substr($value, -1, 1, 'utf-8');
return $strlen == 2 ? $firstStr . str_repeat('*', $strlen - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
}
/**
* 获取当前系统版本号
* @return mixed|null
* @throws Exception
*/
function get_version()
{
//return '1.0.1';
static $version = null;
if ($version) {
return $version;
}
$file = ROOT_PATH . '/version.json';
if (!file_exists($file)) {
throw new Exception('version.json not found');
}
$version = json_decode(file_get_contents($file), true);
if (!is_array($version)) {
throw new Exception('version cannot be decoded');
}
return $version['version'];
}
/**
* 获取全局唯一标识符
* @param bool $trim
* @return string
*/
function getGuidV4($trim = true)
{
// Windows
if (function_exists('com_create_guid') === true) {
$charid = com_create_guid();
return $trim == true ? trim($charid, '{}') : $charid;
}
// OSX/Linux
if (function_exists('openssl_random_pseudo_bytes') === true) {
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
// Fallback (PHP 4.2+)
mt_srand((double)microtime() * 10000);
$charid = strtolower(md5(uniqid(rand(), true)));
$hyphen = chr(45); // "-"
$lbrace = $trim ? "" : chr(123); // "{"
$rbrace = $trim ? "" : chr(125); // "}"
$guidv4 = $lbrace .
substr($charid, 0, 8) . $hyphen .
substr($charid, 8, 4) . $hyphen .
substr($charid, 12, 4) . $hyphen .
substr($charid, 16, 4) . $hyphen .
substr($charid, 20, 12) .
$rbrace;
return $guidv4;
}
function getRandMd5($start = 0, $len = 32)
{
return ($len == 16 ? 'hr' : '') . substr(md5(time() . mt_rand(1000, 9999) . 'hr'), $start, $len);
}
/**
* 时间戳转换日期
* @param $timeStamp
* @return false|string
*/
function format_time($timeStamp)
{
return date('Y-m-d H:i:s', $timeStamp);
}
/**
* 左侧填充0
* @param $value
* @param int $padLength
* @return string
*/
function pad_left($value, $padLength = 2)
{
return \str_pad($value, $padLength, "0", STR_PAD_LEFT);
}
/**
* 获取跳转的真实地址
* 如果访问链接是有跳转的,则获得真实跳转地址。
* public function index()
* {
* return get_redirect_url('http://api.tp5024.com/index.php?s=/oauth/token/a');
* }
* public function a() {
* return redirect('build123');
* }
*/
function get_redirect_url($url)
{
$redirect_url = null;
$url_parts = @parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false;
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)) {
if ( substr($matches[1], 0, 1) == "/" )
return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
else
return trim($matches[1]);
} else {
return false;
}
}
/**
* 获取客户端IP地址
* @return mixed
*/
function getClientIp1()
{
$ip = false;
//客户端IP 或 NONE
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
//多重代理服务器下的客户端真实IP地址(可能伪造),如果没有使用代理,此字段为空
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ips, $ip);
$ip = false;
}
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
//客户端IP 或 (最后一个)代理服务器 IP
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
/**
* 获取客户端IP地址
* @param integer $type
* 0 返回IP地址
* 1 返回IPV4地址数字
* @return mixed
*/
function getClientIp($type = 0) {
$type = $type ? 1 : 0;
$ip = null;
if ($ip !== null) return $ip[$type];
//nginx 代理模式下,获取客户端真实IP
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
// 客户端的ip
elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
// 浏览当前页面的用户计算机的网关
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$pos = array_search('unknown', $arr);
if (false !== $pos) unset($arr[$pos]);
$ip = trim($arr[0]);
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
//浏览当前页面的用户计算机的ip地址
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
// IP地址合法验证
$long = sprintf("%u", ip2long($ip));
$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
return $ip[$type];
}
\ No newline at end of file
... ...
<?php
namespace app\common\behavior;
use think\Log;
use think\Request;
/**
* 应用行为管理
* Class App
* @package app\common\behavior
*/
class App
{
/**
* 应用开始
* @param $dispatch
*/
public function appBegin($dispatch)
{
// 记录访问日志
if (!config('app_debug')) {
$request = Request::instance();
Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'begin');
Log::record('[ HEADER ] ' . var_export($request->header(), true), 'begin');
Log::record('[ PARAM ] ' . var_export($request->param(), true), 'begin');
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\behavior;
/**
* 应用行为管理
* Class Init
* @package app\common\behavior
*/
class Init
{
/**
* 应用初始化
* @param $dispatch
*/
public function run($params)
{
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/23
* Time: 15:40
*/
namespace app\common\controller;
class Controller extends \think\Controller
{
}
\ No newline at end of file
... ...
<?php
namespace app\common\controller;
class ServiceApiController extends Controller
{
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/23
* Time: 15:40
*/
namespace app\common\controller;
class WebController extends Controller
{
public function _emtpy() {
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\enum;
//use MyCLabs\Enum\Enum;
/**
* 枚举类基类
* Class Basics
* @package app\common\enum
*/
abstract class EnumBasics
{
}
\ No newline at end of file
... ...
<?php
namespace app\common\enum;
/**
* 缓存名称枚举类
* Class RedisEnum
* @package app\common\enum
*/
class RedisEnum extends EnumBasics
{
// 权限 urls
const API_URLS = 'api_urls';
// 缓存模块,无需验证 urls
const API_URLS_ALLOW_TABLE = 'api_urls';
const API_URLS_ALLOW_KEY = 'cgi_allow';
const API_URLS_ALLOW_HASH = API_URLS_ALLOW_TABLE . ':' . API_URLS_ALLOW_KEY;
// 缓存模块,无需验证 urls
const API_IPS_ALLOW_TABLE = 'api_urls';
const API_IPS_ALLOW_KEY = 'cgi_allow';
const API_IPS_ALLOW_HASH = API_IPS_ALLOW_TABLE . ':' . API_IPS_ALLOW_KEY;
/**
* 获取枚举数据
* @return array
*/
public static function data()
{
return [
self::API_URLS => [
'name' => '权限 URL',
'value' => self::API_URLS,
]
];
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\exception;
use think\Exception;
/**
* Class BaseException
* 自定义异常类的基类
*/
class BaseException extends Exception
{
public $code = 0;
public $message = 'invalid parameters';
/**
* 构造函数,接收一个关联数组
* @param array $params 关联数组只应包含code、msg,且不应该是空值
*/
public function __construct($params = [])
{
if (!is_array($params)) {
return;
}
if (array_key_exists('code', $params)) {
$this->code = $params['code'];
}
if (array_key_exists('msg', $params)) {
$this->message = $params['msg'];
}
}
}
... ...
<?php
namespace app\common\exception;
use think\exception\Handle;
use think\Log;
use Exception;
/**
* 重写Handle的render方法,实现自定义异常消息
* Class ExceptionHandler
* @package app\common\library\exception
*/
class ExceptionHandler extends Handle
{
private $code;
private $message;
/**
* 输出异常信息
* @param Exception $e
* @return \think\Response|\think\response\Json
*/
public function render(Exception $e)
{
if ($e instanceof BaseException) {
$this->code = $e->code;
$this->message = $e->message;
} else {
if (config('app_debug')) {
return parent::render($e);
}
$this->code = 0;
$this->message = $e->getMessage() ?: '很抱歉,服务器内部错误';
$this->recordErrorLog($e);
}
return json(['code' => $this->code, 'msg' => $this->message]);
}
/**
* 将异常写入日志
* @param Exception $e
*/
private function recordErrorLog(Exception $e)
{
Log::record($e->getMessage(), 'error');
Log::record($e->getTraceAsString(), 'error');
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/28
* Time: 10:56
*/
namespace app\common\model;
use think\Model;
/**
* 基础模型所有模型必须要继承此模型
* Class BaseModel
* @package app\common\model
*/
class BaseModel extends Model
{
public static function init()
{
parent::init();
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
class Cgi extends BaseModel
{
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/28
* Time: 11:04
*/
namespace app\common\model;
class CommApi extends BaseModel
{
public function getOne($where, $field = '*')
{
$data = $this->where($where)->field($field)->find();
if ($data) {
return $data->toArray();
}
return [];
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
/**
* Class Notify
* @package app\common\model
* Date: 2020/7/30
* Time: 11:18
* @author mll
*/
class Notify extends BaseModel
{
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
class ServiceApi extends BaseModel
{
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险车辆信息
* Class Car
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:00
* @author nyq
*/
class Car extends ServiceApi
{
protected $table = "sos_car_car";
protected $pk = "id";
/**
* 函数功能描述 根据用户信息查询车辆
* @param $data
* Date: 2020/7/21
* Time: 16:50
* @author nyq
*/
public function getCar($data) {
$res = static::where($data)->find();
return $res;
}
/**
* 函数功能描述 添加车辆信息
* @param $data
* Date: 2020/7/21
* Time: 16:20
* @author nyq
*/
public function addCar($data) {
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 根据用户信息修改车辆信息
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:22
* @author nyq
*/
public function updateCar($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险支付回调相关信息表
* Class CarCallback
* @package app\common\model\commapi
* Date: 2020/7/22
* Time: 17:20
* @author nyq
*/
class CarCallback extends ServiceApi
{
protected $table="sos_car_callback";
protected $pk = "id";
/**
* 函数功能描述 添加支付信息
* @param $data
* Date: 2020/7/22
* Time: 18:00
* @author nyq
*/
public function addData($data) {
static::insert($data);
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险险种信息
* Class CarInsurance
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:50
* @author nyq
*/
class CarInsurance extends ServiceApi
{
protected $table = "sos_car_insurance";
protected $pk = "id";
/**
* 函数功能描述 根据订单号获取险种信息
* Date: 2020/7/21
* Time: 16:40
* @author nyq
*/
public function getCarInsurance($where) {
$res = static::where($where)->select();
return $res;
}
/**
* 函数功能描述 根据订单号删除险种
* @param $where1
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function getCarInsuranceDel($where) {
$res = static::where($where)->delete();
return $res;
}
/**
* 函数功能描述 添加险种信息
* @param $data
* Date: 2020/7/21
* Time: 16:50
* @author nyq
*/
public function addCarInsurance($data) {
$res = static::insert($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class CarOrder
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:33
* @author nyq
*/
class CarOrder extends ServiceApi
{
protected $table = "sos_car_order";
protected $pk = "id";
/**
* 函数功能描述 根据通知订单号获取订单信息
* Date: 2020/7/21
* Time: 16:40
* @author nyq
*/
public function getCarOrder($where) {
$res = static::where($where)->find();
return $res;
}
/**
* 函数功能描述 根据返回的查询码获取订单信息
* Date: 2020/7/22
* Time: 10:06
* @author nyq
*/
public function getCarOrderList($where) {
$res = static::where($where)->select();
return $res;
}
/**
* 函数功能描述 根据用户信息修改订单信息
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function getCarOrderUpdate($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
/**
* 函数功能描述 添加订单信息
* @param $data
* Date: 2020/7/21
* Time: 16:50
* @author nyq
*/
public function addCarOrder($data) {
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 根据用户信息修改订单信息
* @param $where
* @param $data
* Date: 2020/7/22
* Time: 16:47
* @author gxd
*/
public function getCarOrderUpdateAll($where, $data) {
$res = static::whereIn('appNo',$where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 抽奖
* Class CarOrder
* @package app\common\model\commapi
* Date: 2020/8/25
* Time: 16:33
* @author nyq
*/
class PrizeMember extends ServiceApi
{
protected $table = "sos_prize_member";
protected $pk = "id";
/**
* 函数功能描述 抽奖用户
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function getPrizeMember($code)
{
$user = static::where($code)->select();
return $user;
}
public function getMember($code)
{
$user = static::where($code)->find();
return $user;
}
/**
* 函数功能描述 重置
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function prizeReset($wheres,$data) {
$res = static::where($wheres)->update($data);
return $res;
}
/**
* 函数功能描述 抽奖
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function getPrizeMemberAdd($data) {
$res = static::insertGetId($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class CarOrder
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:33
* @author nyq
*/
class PrizePrize extends ServiceApi
{
protected $table = "sos_prize_prize";
protected $pk = "id";
/**
* 函数功能描述 根据通知订单号获取订单信息
* Date: 2020/7/21
* Time: 16:40
* @author nyq
*/
public function getPrize($code,$offset,$rows)
{
// echo $rows;
$user = static::where($code)->limit($offset,$rows)->select();
//echo static::getLastSql();
return $user;
}
public function getPrizeList($code){
$user = static::where($code)->select();
return $user;
}
public function getPrizePrize($code){
$user = static::where($code)->find();
return $user;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/8/25
* Time: 15:00
* @author nyq
*/
public function prizeAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑奖品
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function prizeUp($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class CarOrder
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:33
* @author nyq
*/
class PrizeRule extends ServiceApi
{
protected $table = "sos_prize_rule";
protected $pk = "id";
/**
* 函数功能描述 查询抽奖规则
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function getPrizeRule()
{
$user = static::find();
return $user;
}
/**
* 函数功能描述 添加规则
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function prizeRullAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑规则
* @param $where
* @param $data
* Date: 2020/8/26
* Time: 16:47
* @author nyq
*/
public function prizeRullEdit($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 抽奖token
* Class token
* @package app\common\model\commapi
* Date: 2020/8/31
* Time: 16:33
* @author nyq
*/
class PrizeToken extends ServiceApi
{
protected $table = "sos_prize_token";
protected $pk = "id";
/**
* 函数功能描述 获取token
* Date: 2020/8/31
* Time: 16:40
* @author nyq
*/
public function getToken()
{
$user = static::find();
return $user;
}
/**
* 函数功能描述 修改token
* Date: 2020/8/31
* Time: 16:40
* @author nyq
*/
public function updataToken($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
/**
* 函数功能描述 添加token
* Date: 2020/8/31
* Time: 15:00
* @author nyq
*/
public function addToken($data)
{
$res = static::insert($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class CarOrder
* @package app\common\model\commapi
* Date: 2020/7/21
* Time: 16:33
* @author nyq
*/
class PrizeWin extends ServiceApi
{
protected $table = "sos_prize_win";
protected $pk = "id";
/**
* 函数功能描述 获取中奖列表
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWin($code,$offset,$rows)
{
$user = static::where($code)->limit($offset,$rows)->order('addTime desc')->select();
return $user;
}
/**
* 函数功能描述 导出数据
* Date: 2020/8/28
* Time: 16:40
* @author nyq
*/
public function getPrizeWinToExcel($code)
{
$user = static::where($code)->select();
return $user;
}
/**
* 函数功能描述 统计数量
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWinCount($code)
{
$user = static::where($code)->count();
return $user;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function prizeAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 获取中奖列表 20 条
* Date: 2020/8/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWinlist($where)
{
if (isset($where) && !empty($where)) {
$user = static::where($where)->select();
}else{
$user = static::limit(20)->order('id asc' )->select();
}
return $user;
}
/**
* 函数功能描述 兑奖接口
* @param $where
* @param $data
* Date: 2020/8/26
* Time: 16:47
* @author nyq
*/
public function winReset($wheres,$data) {
$res = static::where($wheres)->update($data);
return $res;
}
/**
* 函数功能描述 删除抽奖记录
* @param $where
* @param $data
* Date: 2020/8/26
* Time: 16:47
* @author nyq
*/
public function delUser($wheres) {
$res = static::where($wheres)->delete();
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 产品管理
* Class Product
* @package app\common\model\commapi
* Date: 2020/11/2
* Time: 16:33
* @author nyq
*/
class Product extends ServiceApi
{
protected $table = "sos_product_goods";
protected $pk = "id";
/**
* 函数功能描述 添加产品
* Date: 2020/11/2
* Time: 15:00
* @author nyq
*/
public function add($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑奖品
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function productUp($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
/**
* 函数功能描述 获取商品列表
* Date: 2020/11/2
* Time: 16:40
* @author nyq
*/
public function goodsList($code,$offset,$rows){
$user = static::where($code)->limit($offset,$rows)->select();
return $user;
}
public function getGoodsList($code){
$user = static::where($code)->find();
return $user;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 用户管理
* Class Product
* @package app\common\model\commapi
* Date: 2020/11/2
* Time: 16:33
* @author nyq
*/
class ProductOrder extends ServiceApi
{
protected $table = "sos_product_order";
protected $pk = "id";
/**
* 函数功能描述 添加订单
* Date: 2020/11/2
* Time: 15:00
* @author nyq
*/
public function add($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 删除订单
* Date: 2020/11/2
* Time: 15:00
* @author nyq
*/
public function orderDel($data)
{
$res = static::where($data)->delete();
return $res;
}
/**
* 函数功能描述 编辑奖品
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function productUp($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
/**
* 函数功能描述 获取商品列表
* Date: 2020/11/2
* Time: 16:40
* @author nyq
*/
public function orderList($code){
$user = static::where($code)->select();
return $user;
}
public function getGoodsList($code){
$user = static::where($code)->find();
return $user;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 用户管理
* Class Product
* @package app\common\model\commapi
* Date: 2020/11/2
* Time: 16:33
* @author nyq
*/
class ProductUser extends ServiceApi
{
protected $table = "sos_product_user";
protected $pk = "id";
/**
* 函数功能描述 添加用户
* Date: 2020/11/2
* Time: 15:00
* @author nyq
*/
public function add($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑奖品
* @param $where
* @param $data
* Date: 2020/7/21
* Time: 16:47
* @author nyq
*/
public function productUp($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
/**
* 函数功能描述 获取商品列表
* Date: 2020/11/2
* Time: 16:40
* @author nyq
*/
public function getUserlist($code,$offset,$rows){
$user = static::alias("user")->where($code)->limit($offset,$rows);
$res= $user->join("sos_product_order or", "or.user_id=user.id")->join("sos_product_goods go", "or.goods_id=go.id","LEFT")
->field("user.*,or.order_code,or.num,or.price,go.name as goods_name")
->select();
return $res;
}
public function getUserlistToEx(){
$user = static::alias("user");
$res= $user->join("sos_product_order or", "or.user_id=user.id")->join("sos_product_goods go", "or.goods_id=go.id","LEFT")
->field("user.*,or.order_code,or.num,or.price,go.name as goods_name")
->select();
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 抽奖
* Class turnPrize
* @package app\common\model\commapi
* Date: 2020/9/25
* Time: 16:33
* @author nyq
*/
class TurnPrizeMember extends ServiceApi
{
protected $table = "sos_prize_turn_member";
protected $pk = "id";
/**
* 函数功能描述 抽奖用户
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function getPrizeMember($code)
{
$user = static::where($code)->select();
return $user;
}
public function getMember($code)
{
$user = static::where($code)->find();
return $user;
}
/**
* 函数功能描述 重置
* @param $where
* @param $data
* Date: 2020/9/21
* Time: 16:47
* @author nyq
*/
public function prizeReset($wheres,$data) {
$res = static::where($wheres)->update($data);
return $res;
}
/**
* 函数功能描述 抽奖
* @param $where
* @param $data
* Date: 2020/9/21
* Time: 16:47
* @author nyq
*/
public function getPrizeMemberAdd($data) {
$res = static::insertGetId($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class turnPrize
* @package app\common\model\commapi
* Date: 2020/9/21
* Time: 16:33
* @author nyq
*/
class TurnPrizePrize extends ServiceApi
{
protected $table = "sos_prize_turn_prize";
protected $pk = "id";
/**
* 函数功能描述 根据条件获取奖品列表
* Date: 2020/9/21
* Time: 16:40
* @author nyq
*/
public function getPrize($code,$offset,$rows)
{
$user = static::where($code)->limit($offset,$rows)->select();
return $user;
}
public function getPrizeList($code){
$user = static::where($code)->select();
return $user;
}
public function getPrizePrize($code){
$user = static::where($code)->find();
return $user;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/9/25
* Time: 15:00
* @author nyq
*/
public function prizeAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑奖品
* @param $where
* @param $data
* Date: 2020/9/21
* Time: 16:47
* @author nyq
*/
public function prizeUp($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class turnPrize
* @package app\common\model\commapi
* Date: 2020/9/21
* Time: 16:33
* @author nyq
*/
class TurnPrizeRule extends ServiceApi
{
protected $table = "sos_prize_turn_rule";
protected $pk = "id";
/**
* 函数功能描述 查询抽奖规则
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function getPrizeRule()
{
$user = static::find();
return $user;
}
/**
* 函数功能描述 添加规则
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function prizeRullAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 编辑规则
* @param $where
* @param $data
* Date: 2020/9/26
* Time: 16:47
* @author nyq
*/
public function prizeRullEdit($where, $data) {
$res = static::where($where)->update($data);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model\serviceapi;
use app\common\model\ServiceApi;
/**
* 功能描述 华安车险订单信息
* Class turnPrize
* @package app\common\model\commapi
* Date: 2020/9/21
* Time: 16:33
* @author nyq
*/
class TurnPrizeWin extends ServiceApi
{
protected $table = "sos_prize_turn_win";
protected $pk = "id";
/**
* 函数功能描述 获取中奖列表
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWin($code,$offset,$rows)
{
$user = static::field('*,count(*) as num')->where($code)->limit($offset,$rows)->group('member_id')->order('addTime desc')->select();
// return $this->getLastSql();
return $user;
}
/**
* 函数功能描述 导出数据
* Date: 2020/9/28
* Time: 16:40
* @author nyq
*/
public function getPrizeWinToExcel($code)
{
$user = static::where($code)->select();
return $user;
}
/**
* 函数功能描述 统计数量
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWinCount($code)
{
$user = static::where($code)->count();
return $user;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function prizeAdd($data)
{
$res = static::insertGetId($data);
return $res;
}
/**
* 函数功能描述 获取中奖列表 20 条
* Date: 2020/9/25
* Time: 16:40
* @author nyq
*/
public function getPrizeWinlist($where)
{
if (isset($where) && !empty($where)) {
$user = static::where($where)->order('addTime desc' )->select();
}else{
$user = static::where('is_del !=1')->limit(20)->order('id asc' )->select();
}
return $user;
}
/**
* 函数功能描述 兑奖接口
* @param $where
* @param $data
* Date: 2020/9/26
* Time: 16:47
* @author nyq
*/
public function winReset($wheres,$data) {
$res = static::where($wheres)->update($data);
return $res;
}
/**
* 函数功能描述 删除抽奖记录
* @param $where
* @param $data
* Date: 2020/9/26
* Time: 16:47
* @author nyq
*/
public function delUser($wheres) {
$res = static::where($wheres)->delete();
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\service;
use app\common\exception\BaseException;
trait Render
{
/**
* 输出错误信息
* @param int $code
* @param $msg
* @throws BaseException
*/
protected function throwError($msg, $code = 0)
{
throw new BaseException(['code' => $code, 'msg' => $msg]);
}
/**
* 返回封装后的 API 数据
* @param int $code
* @param string $msg
* @param array $data
* @return array
*/
protected function renderJson($code = 0, $msg = '', $data = [])
{
return compact('code', 'msg', 'data');
}
/**
* 返回成功json
* @param array $data
* @param string|array $msg
* @return array
*/
protected function renderSuccess($data = [], $msg = 'success', $code = 0)
{
return $this->renderJson($code, $msg, $data);
}
/**
* 返回操作失败json
* @param string $msg
* @param array $data
* @return array
*/
protected function renderError($msg = 'error', $code = 1, $data = [])
{
return $this->renderJson($code, $msg, $data);
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/28
* Time: 18:22
*/
namespace app\common\validate;
use think\Validate;
class BaseValidate extends Validate
{
/**
* 验证手机号是否正确
* @param $value
* @param $rule
* @param $data
*/
protected function checkPhone($value, $rule, $data)
{
return preg_match("/^1[3456789]\d{9}$/", $value) ? true : "手机号不正确";
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
return [
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
// 应用调试模式
'app_debug' => true,
// 应用Trace
'app_trace' => false,
// 应用模式状态
'app_status' => '',
// 是否支持多模块
'app_multi_module' => true,
// 入口自动绑定模块
'auto_bind_module' => false,
// 注册的根命名空间
'root_namespace' => [],
// 扩展函数文件
'extra_file_list' => [THINK_PATH . 'helper' . EXT],
// 默认输出类型
'default_return_type' => 'json',
// 默认AJAX 数据返回格式,可选json xml ...
'default_ajax_return' => 'json',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
// 默认时区
'default_timezone' => 'PRC',
// 是否开启多语言
'lang_switch_on' => false,
// 默认全局过滤方法 用逗号分隔多个
'default_filter' => 'htmlspecialchars',
// 默认语言
'default_lang' => 'zh-cn',
// 应用类库后缀
'class_suffix' => false,
// 控制器类后缀
'controller_suffix' => false,
// +----------------------------------------------------------------------
// | 模块设置
// +----------------------------------------------------------------------
// 默认模块名
'default_module' => 'web',
// 禁止访问模块
'deny_module_list' => ['common'],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 默认验证器
'default_validate' => '',
// 默认的空控制器名
'empty_controller' => 'Error',
// 操作方法后缀
'action_suffix' => '',
// 自动搜索控制器
'controller_auto_search' => false,
// +----------------------------------------------------------------------
// | URL设置
// +----------------------------------------------------------------------
// PATHINFO变量名 用于兼容模式
'var_pathinfo' => 's',
// 兼容PATH_INFO获取
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
// pathinfo分隔符
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => '',
// URL普通方式参数 用于自动生成
'url_common_param' => false,
// URL参数方式 0 按名称成对解析 1 按顺序解析
'url_param_type' => 0,
// 是否开启路由
'url_route_on' => true,
// 路由使用完整匹配
'route_complete_match' => false,
// 路由配置文件(支持配置多个)
'route_config_file' => ['route'],
// 是否开启路由解析缓存
'route_check_cache' => false,
// 是否强制使用路由
'url_route_must' => false,
// 域名部署
'url_domain_deploy' => false,
// 域名根,如thinkphp.cn
'url_domain_root' => '',
// 是否自动转换URL中的控制器和操作名
'url_convert' => true,
// 默认的访问控制器层
'url_controller_layer' => 'controller',
// 表单请求类型伪装变量
'var_method' => '_method',
// 表单ajax伪装变量
'var_ajax' => '_ajax',
// 表单pjax伪装变量
'var_pjax' => '_pjax',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
'template' => [
// 模板引擎类型 支持 php think 支持扩展
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写
'auto_rule' => 1,
// 模板路径
'view_path' => '',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DS,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
],
// 视图输出字符串内容替换
'view_replace_str' => [],
// 默认跳转页面对应的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
// +----------------------------------------------------------------------
// | 异常及错误设置
// +----------------------------------------------------------------------
// 异常页面的模板文件
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '\\app\\common\\exception\\ExceptionHandler',
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
'log' => [
// 日志记录方式,内置 file socket 支持扩展
'type' => 'File',
// 日志保存目录
'path' => LOG_PATH,
// 日志记录级别
'level' => [],
// error和sql日志单独记录
'apart_level' => ['begin', 'error', 'sql', 'info'],
],
// +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效
// +----------------------------------------------------------------------
'trace' => [
// 内置Html Console 支持扩展
'type' => 'Html',
],
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
'cache' => [
// 使用复合缓存类型
'type' => 'complex',
'default' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
],
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => RUNTIME_PATH . 'file/',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
],
// redis缓存
'redis' => [
// 驱动方式
'type' => 'redis',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 服务器地址
'host' => '127.0.0.1',
],
],
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
'session' => [
'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// SESSION 前缀
'prefix' => 'api',
// 驱动方式 支持redis memcache memcached
'type' => '',
// 是否自动开启 SESSION
'auto_start' => true,
],
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
'cookie' => [
// cookie 名称前缀
'prefix' => '',
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => '',
// 是否使用 setcookie
'setcookie' => true,
],
//分页配置
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
],
];
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
return [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '49.232.59.136',
// 数据库名
'database' => 'prize',
// 用户名
'username' => 'prize',
// 密码
'password' => 'wfKsEGRtm2NPwWXs',
// 端口
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'sos_',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 自动读取主库数据
'read_master' => false,
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'collection',
// 自动写入时间戳字段
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
];
... ...
<?php
return [
"appid" => "999999", //上线请修改
"appsecret" => "999999", //上线请修改
];
... ...
<?php
namespace app\products\controller;
use app\products\validate\Car as CarValidate;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
header("Content-type: text/html; charset=utf-8");
/**
* 功能描述 华安车险
* Class Car
* @package app\products\controller
* Date: 2020/8/3
* Time: 17:00
* @author nyq
*/
class Car extends BaseController
{
//请求地址
//private $api_url = "https://api.sosyun.com//serviceapi/car/";
//private $api_url = "http://demo8.xiaochakeji.com/serviceapi/car/";
private $api_url = "www.aisigit.com/products/car/";
//回调查询接口
private $api_back_url = "http://demo8.xiaochakeji.com/notify/car/";
//private $api_back_url = "https://api.sosyun.com//notify/car/";
/**
* 函数功能描述 获取订单信息
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function carOrder(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['id']=2;
$data['offset']=$offset;
$data['rows']=$rows;
$res = MCurl::instance($this->api_url."carOrder")->post($data);
$json=json_decode($res);
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 获取订单详情
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function carOrderDetail(Request $request)
{
$data = $request->param();
$id['id']=$data['id'];
$res = MCurl::instance($this->api_url."carOrderDetail")->post($id);
$res = json_decode($res, true);
$use_res = MCurl::instance($this->api_url."selMember")->post($id);
$use_res = json_decode($use_res, true);
$status_arr = ['转人工核保','','','打回修改','拒保','','','待支付','支付成功','支付失败'];
foreach($res as $k => $v){
if($v['riskCode']=='0302'){
$res[$k]['type']='商业险';
}elseif($v['riskCode']=='0301'){
$res[$k]['type']='交强险';
}
$res[$k]['appName']=$use_res['appName'];
$res[$k]['insuredName']=$use_res['insuredName'];
$res[$k]['status_arr'] = $status_arr[$v['status']];
$res[$k]['operDate'] =date("Y-m-d H:i:s",$v['operDate']);
}
return $res;
}
/**
* 函数功能描述 搜索
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function select(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['id']=2;
$data['offset']=$offset;
$data['rows']=$rows;
$res = MCurl::instance($this->api_url."carOrder")->post($data);
$json=json_decode($res);
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
}
/**
* 函数功能描述 支付申请
* Date: 2020/8/11
* Time: 10:00
* @author nyq
*/
public function pay(Request $request)
{
$data = $request->param();
//查询订单信息及金额
$order_res = MCurl::instance($this->api_url."pay")->post($data);
$use_res = MCurl::instance($this->api_url."selMember")->post($data);
$order_json=json_decode($order_res,true);
$use_json=json_decode($use_res,true);
$json['jqAppNo']=$order_json[0]['appNo'];
$json['jqAmount']=$order_json[0]['premium']+$order_json[0]['currentTax'];
$json['jqAppName']=$use_json['appName'];
$json['syAppNo']=$order_json[1]['appNo'];
$json['syAmount']=$order_json[1]['premium'];
$json['syAppName']=$use_json['appName'];
$arr['data']=json_encode($json);
$res = MCurl::instance($this->api_url."launchPayment")->post($arr);
$res=json_decode($res, true);
return $res;
}
/**
* 函数功能描述 获取车型
* Date: 2020/8/03
* Time: 17:10
* @author nyq
*/
public function carmodel(Request $request)
{
$data = $request->param();
$validtaor = new CarValidate();
$res = $validtaor->scene("carmodel")->check($data);
if ($res === false) {
return ['errcode' => 100, 'errmsg' => $validtaor->getError()];
}
if (in_array("undefined", $data)) {
return ["errcode" => 100, "errmsg" => "提交数据存在问题"];
}
$res = MCurl::instance($this->api_url."carmodel")->post($data);
$res = json_decode($res, true);
return $res;
}
/**
* 函数功能描述 车险保费计算
* Date: 2020/8/4
* Time: 09:12
* @author nyq
*/
public function premium(Request $request)
{
$json = $request->param(); // 报错 Array to string conversion
$data = $request->param('data');
//数据特殊符号转义
$data = htmlspecialchars_decode($data);
$data = json_decode($data, true);
//处理校验数据
$arr=$this->premiumArray($data);
$validtaor = new CarValidate();
$res = $validtaor->scene("premium")->check($arr);
if ($res === false) {
return ['errcode' => 100, 'errmsg' => $validtaor->getError()];
}
if (in_array("undefined", $arr)) {
return ["errcode" => 100, "errmsg" => "提交数据存在问题"];
}
$res = MCurl::instance($this->api_url."premium")->post($json);
$res = json_decode($res, true);
return $res;
}
/**
* 函数功能描述 车险提交核保
* Date: 2020/8/03
* Time: 15:10
* @author nyq
*/
public function underwrite()
{
$json = $this->request->post();
$base = $this->request->post('data');
$base = htmlspecialchars_decode($base);
$base = json_decode($base, true);
//进行数据校验
$validtaor = new CarValidate();
$res = $validtaor->scene("underwrite")->check($base);
if ($res === false) {
return ['errcode' => 100, 'errmsg' => $validtaor->getError()];
}
$res = MCurl::instance($this->api_url."underwrite")->post($json);
$res=json_decode($res, true);
return $res;
}
/**
* 函数功能描述 支付/核保回调接口
* Date: 2020/8/4
* Time: 17:00
* @author nyq
*/
public function get_status()
{
$base = $this->request->post();
$res = MCurl::instance($this->api_back_url."get_status")->post($base);
$res=json_decode($res, true);
return $res;
}
/**
* 函数功能描述 支付申请接口
* Date: 2020/8/4
* Time: 16:30
* @author nyq
*/
public function payment()
{
$json = $this->request->post();
$base = $this->request->post('data');
$base = htmlspecialchars_decode($base);
$base=json_decode($base, true);
//进行数据校验
$validator = new CarValidate();
$res = $validator->scene("pay")->check($base);
if ($res === false) {
return ['errcode' => 100, 'errmsg' => $validator->getError()];
}
$res = MCurl::instance($this->api_url."payment")->post($json);
$res=json_decode($res, true);
return $res;
}
/**
* 函数功能描述 整理车险检验信息
* Date: 2020/7/21
* Time: 11:12
* @author nyq
*/
public function premiumArray($arr){
//车主信息
$owner=$arr['owner'];
//投保人
$applacation=$arr['applacation'];
//被保人
$insured=$arr['insured'];
//车辆信息
$vhl=$arr['vhl'];
//base
//$base=$arr['base'];
$data=array_merge($owner,$applacation,$insured,$vhl);
//险种信息
if(count($arr['riskList'])>1){
if($arr['riskList'][0]['riskCode'] != '' && $arr['riskList'][1]['riskCode'] != ''){
$data['xz']='true';
}else{
$data['xz']='';
}
}else{
$data['xz']='';
}
$data['cityCode']=$arr['cityCode'];
$data['modelName']=$arr['modelName'];
$data['email']=$arr['email'];
return $data;
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\controller;
use app\common\controller\ProductsController;
/**
* 功能描述 换取access_token
* Class Controller
* @package app\products\controller
* Date: 2020/7/14
* Time: 16:06
* @author gxd
*/
class Controller extends ProductsController
{
protected $appid = "";
protected $appsecret = "";
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->appid = config("appid");
$this->appsecret = config("appsecret");
$this->allOrigin();
}
public function allOrigin() {
header('Content-Type: text/html;charset=utf-8');
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\controller;
use app\common\model\serviceapi\Product as ProductModel;
use app\common\model\serviceapi\ProductUser as ProductUserModel;
use app\common\model\serviceapi\ProductOrder as ProductOrderModel;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 妇记通获客
* Class Product
* @package app\FuJiTong\controller
* Date: 2021/5/6
* Time: 10:00
* @author nyq
*/
class FuJiTong extends BaseController
{
private $api_domain ="www.aisigit.com/products/fu/customer_list"; //测试平台
//private $api_domain = "http://hzy.sosyun.com/products/fu/customer_list";
/**
* 函数功能描述 获取客户列表
* Date: 2021/5/6
* Time: 10:00
* @author nyq
*/
public function customer_list(Request $request)
{
$data = $request->param();
//return json($data);
Cookie::set('fu_data', $data);
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$json=[
"offset"=>$offset,
"rows"=>$rows,
"result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
"type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
"start"=>!empty($data['start']) ? $data['start'] : '',
"end"=>!empty($data['end']) ? $data['end'] : '',
"phone"=>!empty($data['phone']) ? $data['phone'] : '',
];
// return json($json);
$data_http = http_build_query($json);
$row=MCurl::instance($this->api_domain)->post($data_http);
$data_list=json_decode($row,true);
$data_json=$data_list['rows'];
foreach($data_json as $key=>$val ){
$data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
}
$result["total"] =$data_list['total'];
$result['rows']=$data_json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
$data= Cookie::get('fu_data');
$json=[
"offset"=>1,
"rows"=>1,
"result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
"type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
"start"=>!empty($data['start']) ? $data['start'] : '',
"end"=>!empty($data['end']) ? $data['end'] : '',
"phone"=>!empty($data['phone']) ? $data['phone'] : '',
'to_excel'=>1
];
$data_http = http_build_query($json);
$row=MCurl::instance($this->api_domain)->post($data_http);
$data_list=json_decode($row,true);
$data_json=$data_list['rows'];
foreach($data_json as $key=>$val ){
$data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '用户名称')
->setCellValue('B1', '性别')
->setCellValue('C1', '电话')
->setCellValue('D1', '证件号码')
->setCellValue('E1', '推送结果')
->setCellValue('F1', '推送时间');
$rowIndex = 2;
foreach ($data_json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['username'])
->setCellValue('B' . $rowIndex, $v['sex'])
->setCellValue('C' . $rowIndex, $v['phone'])
->setCellValue('D' . $rowIndex, $v['certificateNo'].',')
->setCellValue('E' . $rowIndex, $v['result'].',')
->setCellValue('F' . $rowIndex, $v['create_time']);
$rowIndex++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$filename = '用户信息列表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\controller;
use app\products\validate\Car as CarValidate;
use app\serviceapi\controller\Prize as prizeModel;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 抽奖管理
* Class Car
* @package app\products\controller
* Date: 2020/8/25
* Time: 10:00
* @author nyq
*/
class Prize extends BaseController
{
//正式
private $appid = 'wx3e41adc018004fd1';
private $appsecrt = 'f072ba0a6dbb24a2f6b504259367ecfc';
//测试
// private $appid = 'wx8acc3fd862a42941';
// private $appsecrt = '04958b3c06a73aca04c2d5d0cfb4fd11';
//请求地址
//private $api_url = "http://demo8.xiaochakeji.com/serviceapi/prize/";
//查询接口
//private $api_url = "www.aisigit.com/products/prize/";
//private $api_url = "http://hzy.sosyun.com/products/prize/";
//private $api_url = "https://api.sosyun.com//serviceapi/prize/";
/**
* 函数功能描述 微信分享获取AccessToken
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function getAccessToken() {
//查询数据表里面的值
$data['appid']= $this->appid;
$data['appsecrt']= $this->appsecrt;
$prize_win_model = new prizeModel();
$info = $prize_win_model->getAccessToken();
//$info = MCurl::instance($this->api_url."getAccessToken")->post($data);
$info = json_decode($info,true);
if(empty($info) || $info['expires_in'] < time()){
//获取token的值
$url_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->appsecrt;
$tmp = $this->curl_get($url_token); //json格式
$obj = json_decode($tmp,true);
if($obj['access_token'] != null){
$data['access_token'] = $obj['access_token'];
$data['expires_in'] = time() + $obj['expires_in'];
if($info){
$data['id'] = $info['id'];
$info = $prize_win_model->updateAccessToken($data);
//$arr = MCurl::instance($this->api_url."updateAccessToken")->post($data);
}else{
$info = $prize_win_model->addAccessToken($data);
//$arr = MCurl::instance($this->api_url."addAccessToken")->post($data);
}
return $data;
}else return 'error';
}else return $info;
}
/**
* 函数功能描述 微信分享获取ticket
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function getTicket(){
$token = $this->getAccessToken();
if(empty($token['jsapi_ticket']) || $token['expires_in'] < time()){
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$token['access_token']."&type=jsapi";
$tmp = $this->curl_get($url); //json格式
// return $tmp;
$obj = json_decode($tmp,true);
$data['id'] = $token['id'];
$data['jsapi_ticket'] = $obj['ticket'];
$prize_win_model = new prizeModel();
$info = $prize_win_model->updateAccessToken($data);
//$arr = MCurl::instance($this->api_url."updateAccessToken")->post($data);
return $obj['ticket'];
}else{
return $token['jsapi_ticket'];
}
}
/**
* 函数功能描述 微信分享获取sdk
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function generateSign(Request $request){
$dataurl = $request->param('url');
$url=str_replace('amp;','',$dataurl);
$noncestr = uniqid();
$timestamp = time();
$ticket = $this->getTicket();
// return $ticket;
if ($ticket) {
$str = 'jsapi_ticket='.$ticket.'&noncestr='.$noncestr.'&timestamp='.$timestamp.'&url='.$url;
//echo $str;die;
$signature = sha1($str);
$data['str'] = $str;
$data['ticket'] = $ticket;
$data['nonceStr'] = $noncestr;
$data['timestamp'] = $timestamp;
$data['signature'] = $signature;
$data['appId'] = $this->appid;
$data['link'] = $url;
return $data;
}
}
/**
* 函数功能描述 抽奖用户模拟微信授权 返回 openid
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function getWxCode(Request $request)
{
$data = $request->param();
$code=$data['code'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->appid . "&secret=" . $this->appsecrt . "&code=$code&grant_type=authorization_code";
$r = $this->curl_get($url);
$openid=json_decode($r,true);
return $openid;
}
/**
* 函数功能描述 获取订单信息 / 获取奖品列表接口
* Date: 2020/8/27
* Time: 10:00
* @author nyq
*/
public function prize_list(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeList($data);
//$res = MCurl::instance($this->api_url."prizeList")->post($data);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
if($val['display'] ==0){
$json[$key]['display']="已发布";
}else{
$json[$key]['display']="未发布";
}
}
//var_dump($json);die;
// $last_names = array_column($json,'addTime');
// array_multisort($last_names,SORT_DESC,$json);
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function prize_add(Request $request)
{
$data = $request->param();
$data['addTime']=time();
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeAdd($data);
//$res = MCurl::instance($this->api_url."prizeAdd")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'修改成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'修改失败'
];
}
return $data;
}
/**
* 函数功能描述 规则设置 // 获取抽奖规则接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule(Request $request)
{
//$data = $request->param();
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeRule();
//$res = MCurl::instance($this->api_url."prizeRule")->post($data);
$json=json_decode($res,true);
$code="fg5Fu7Is9aHJ5ug5".time();
$json['openid']=$code;
return $json;
// $json=json_encode($res);
// $aa= html_entity_decode($json);
// //数据特殊符号转义
// $aa = htmlspecialchars_decode($aa);
// return $aa;
}
/**
* 函数功能描述 修改规则设置
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule_edit(Request $request)
{
$data = $request->param();
$data['addTime']=time();
if(isset($data['open']) && $data['open']=="on"){
$data['open']=1;
}else{
$data['open']=0;
}
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeRuleEdit($data);
//$res = MCurl::instance($this->api_url."prizeRuleEdit")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'修改成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'修改失败'
];
}
return $data;
}
/**
* 函数功能描述 重置抽奖次数
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_reset(Request $request)
{
//$data = $request->param();
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeReset();
//$res = MCurl::instance($this->api_url."prizeReset")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'重置成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'重置失败'
];
}
return $data;
}
/**
* 函数功能描述 中奖用户列表
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_user_list(Request $request)
{
$data = $request->param();
$page = $data['page'];
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
Cookie::set('data', $data);
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeUserList($data);
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
//$res=json_decode($res,true);
$json=$res['rows'];
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
if($val['receive'] ==0){
$json[$key]['receive']="未领取";
}else{
$json[$key]['receive']="已领取";
}
}
$last_names = array_column($json,'addTime');
array_multisort($last_names,SORT_DESC,$json);
// $count = MCurl::instance($this->api_url."prizeUserCount")->post($data);
// $count=json_decode($count,true);
// $result["total"] =$count;
// $result['rows']=$json;
$result["total"] =$res['total'];
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 删除中奖用户列表
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function del_user()
{
$data = $this->request->post();
$prize_win_model = new prizeModel();
$res = $prize_win_model->delUser($data);
//$res = MCurl::instance($this->api_url."delUser")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'删除成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'删除失败'
];
}
return $data;
}
/**
* 函数功能描述 文件上传
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function uploadFileImgs(){
$files = request()->file('files');
$path = input('path');
if($files){
$imgarr = [];
foreach($files as $file){
$info = $file->validate(['size'=>204800000,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public/web/' . DS . 'prize');
if($info){
$newurl = '/web/prize/'.$info->getSaveName();
$img= str_replace('\\','/',$newurl);
$imgarr[]=$img;
}
}
return json_encode($imgarr);
}else{
echo '没有图片上传';
}
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
//$data = $this->request->Post();
$data= Cookie::get('data');
$data['to_excel']=1;
$prize_win_model = new prizeModel();
$json = $prize_win_model->prizeUserList($data);
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
//$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '用户名')
->setCellValue('B1', '电话')
->setCellValue('C1', '奖品名称')
->setCellValue('D1', '部门')
->setCellValue('E1', '时间');
$rowIndex = 2;
foreach ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['uname'])
->setCellValue('B' . $rowIndex, $v['phone'])
->setCellValue('C' . $rowIndex, $v['prizeName'])
->setCellValue('D' . $rowIndex, $v['source'])
->setCellValue('E' . $rowIndex, $v['addTime']);
$rowIndex++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$filename = '抽奖用户数据表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
/**
* 函数功能描述 获取抽奖规则接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule_api(Request $request)
{
$data = $request->param();
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeRuleEdit($data);
//$res = MCurl::instance($this->api_url."prizeRuleEdit")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'重置成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'重置失败'
];
}
return $data;
}
/**
* 函数功能描述 首次进入 合适身份信息 接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function sel_prize_member(Request $request)
{
$data = $request->param();
//给我 openID number
//查看当前用户是否存在
$prize_win_model = new prizeModel();
$res = $prize_win_model->selPrizeMember($data);
// $res = MCurl::instance($this->api_url."selPrizeMember")->post($data);
// $json=json_decode($res,true);
return $res;
}
/**
* 函数功能描述 抽奖接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function luck_draw(Request $request)
{
//传递 openID prize_id
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new prizeModel();
$res = $prize_win_model->luckDraw($data);
//$res = MCurl::instance($this->api_url."luckDraw")->post($data);
//$json=json_decode($res,true);
//传递 openID prize_id
return $res;
}
/**
* 函数功能描述 获取最新的20条中奖列表 / 个人的奖品列表 接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function win_list(Request $request)
{
//传递 openID
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new prizeModel();
$res = $prize_win_model->prizeWinList($data);
// $res = MCurl::instance($this->api_url."prizeWinList")->post($data);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
//传递 openID prize_id
return $json;
}
/**
* 函数功能描述 兑奖接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function cash_prize(Request $request)
{
//传递 openID
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new prizeModel();
$res = $prize_win_model->cashPrize($data);
//$res = MCurl::instance($this->api_url."cashPrize")->post($data);
$json=json_decode($res,true);
if($json==1){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
//传递 openID prize_id
return $data;
}
/**
* 发起GET请求
* @param string $url 请求地址
* @param array $data 请求参数
* @param string $cookiePath 请求所保存的cookie路径
*/
function curl_get($url, $data=[], $cookiePath = '')
{
if(count($data)!=0) {
$url = get_query_url($url, $data);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\controller;
use app\common\model\serviceapi\Product as ProductModel;
use app\common\model\serviceapi\ProductUser as ProductUserModel;
use app\common\model\serviceapi\ProductOrder as ProductOrderModel;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 产品管理
* Class Product
* @package app\products\controller
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
class Product extends BaseController
{
private $api_back_url = "http://sosapi.com/commapi/generator_data/sosBxCarInfoAdd";
public function carOrder()
{
//$res = MCurl::instance($this->api_back_url)->post($data);
$data=[];
$res=[];
for($i=0;$i<10;$i++){
$res[$i] = json_decode(MCurl::instance($this->api_back_url)->post($data),true);
}
$this->to($res);
var_dump($res);
die;
//var_dump();
//echo 111;die;
return $res;
}
public function to($json)
{
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '用户名')
->setCellValue('B1', '车牌')
->setCellValue('C1', '身份证')
->setCellValue('D1', '电话')
->setCellValue('E1', '年龄')
->setCellValue('F1', '性别');
$rowIndex = 2;
foreach ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['uname'])
->setCellValue('B' . $rowIndex, $v['pai'])
->setCellValue('C' . $rowIndex, $v['shen'])
->setCellValue('D' . $rowIndex, $v['tel'])
->setCellValue('E' . $rowIndex, $v['age'])
->setCellValue('F' . $rowIndex, $v['sex']);
$rowIndex++;
}
// echo 3321;die;
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(100
);
// $objPHPExcel->getActiveSheet()->getStyle('C')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$filename = '用户数据表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
/**
* 函数功能描述 删除订单
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function order_del()
{
$data = $this->request->post();
$product_order_model = new ProductOrderModel();
$res = $product_order_model->orderDel($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'删除成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'删除失败'
];
}
return $data;
}
/**
* 函数功能描述 生成订单
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function addOrde(Request $request)
{
$data = $request->param();
//用户信息
$user['name']=$data['name'];
$user['phone']=$data['phone'];
// $user['sheng']=$data['sheng'];
// $user['shi']=$data['shi'];
// $user['qu']=$data['qu'];
$user['address']=$data['address'];
$user['addTime']=time();
$product_user_model = new ProductUserModel();
$res = $product_user_model->add($user);
//订单信息
$order['order_code']=time().mt_rand(999, 9999);
$order['user_id']=$res;
$order['goods_id']=$data['goods_id'];
$order['num']=$data['num'];
$order['price']=$data['price'];
// $order['sheng']=$data['sheng'];
// $order['shi']=$data['shi'];
// $order['qu']=$data['qu'];
$order['address']=$data['address'];
$order['addTime']=time();
$order['upTime']=time();
$product_order_model = new ProductOrderModel();
$order_res = $product_order_model->add($order);
$json=json_decode($order_res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
return $data;
}
/**
* 函数功能描述 获取订单列表
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function get_order_list(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$where=[];
$product_user_model = new ProductUserModel();
$res = $product_user_model->getUserlist($where,$data['offset'],$data['rows']);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
//$json[$key]['address']=$json[$key]['sheng'].$json[$key]['shi'].$json[$key]['qu'].$json[$key]['address'];
}
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 根据id查询商品信息
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function get_one_list(Request $request)
{
$data = $request->param();
$product_model = new ProductModel();
$res = $product_model->getGoodsList($data);
$res['content'] = htmlspecialchars_decode($res['content']);
$img[]=explode(',',$res['images']);
$res['img']=$img[0][0];
$res['img2']=$img[0][1];
$res['img3']=$img[0][2];
unset($res['images']);
return $res;
}
/**
* 函数功能描述 获取商品列表
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function goods_list(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$product_model = new ProductModel();
$where=[];
$res = $product_model->goodsList($where,$data['offset'],$data['rows']);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 添加商品
* Date: 2020/11/02
* Time: 10:00
* @author nyq
*/
public function goods_add(Request $request)
{
$data = $request->param();
$data['images']=$data['img'].','.$data['img2'].','.$data['img3'];
unset($data['img'],$data['img2'],$data['img3']);
$product_model = new ProductModel();
if(isset($data['goods_id']) && !empty($data['goods_id'])){
$data['upTime']=time();
$where['id']=$data['goods_id'];
unset($data['goods_id']);
$res = $product_model->productUp($where,$data);
}else{
unset($data['goods_id']);
$data['addTime']=time();
$data['upTime']=time();
$res = $product_model->add($data);
}
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
return $data;
}
/**
* 函数功能描述 文件上传
* Date: 2020/11/02
* Time: 10:00
* @author nyq
*/
public function uploadFileImgs(){
$files = request()->file('files');
$path = input('path');
if($files){
$imgarr = [];
foreach($files as $file){
$info = $file->validate(['size'=>204800000,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public/web/' . DS . 'product');
if($info){
$newurl = '/web/product/'.$info->getSaveName();
$img= str_replace('\\','/',$newurl);
$imgarr[]=$img;
}
}
return json_encode($imgarr);
}else{
echo '没有图片上传';
}
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
//$data = $this->request->Post();
// $data= Cookie::get('data');
// $data['to_excel']=1;
$product_user_model = new ProductUserModel();
$json = $product_user_model->getUserlistToEx();
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
//$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
$json[$key]['address']=$json[$key]['sheng'].$json[$key]['shi'].$json[$key]['qu'].$json[$key]['address'];
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '订单编号')
->setCellValue('B1', '商品名称')
->setCellValue('C1', '用户名')
->setCellValue('D1', '电话')
->setCellValue('E1', '详细地址')
->setCellValue('F1', '产品数量')
->setCellValue('G1', '总金额')
->setCellValue('H1', '下单时间');
$rowIndex = 2;
foreach ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['order_code'])
->setCellValue('B' . $rowIndex, $v['goods_name'])
->setCellValue('C' . $rowIndex, $v['name'])
->setCellValue('D' . $rowIndex, $v['phone'])
->setCellValue('E' . $rowIndex, $v['address'])
->setCellValue('F' . $rowIndex, $v['num'])
->setCellValue('G' . $rowIndex, $v['price'])
->setCellValue('H' . $rowIndex, $v['addTime']);
$rowIndex++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
$filename = '产品订单列表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/24
* Time: 15:30
*/
namespace app\products\controller;
use app\web\controller\BaseController;
use think\Db;
use think\Request;
class Role extends BaseController
{
public function user_management(){
return $this->fetch();
}
//获取用户列表
public function getUsers(){
//$org_id = session('organization.org_id');
$list= Db::table('sos_user_role')->select()->toArray();
$type=['','试用期','正式员工','已离职'];
foreach($list as $key=>$val ){
$list[$key]['sex']=$val['sex'] == 1? '男' : '女';
//所属机构
if($val['mechanism'] != 0){
$mechanism= Db::table('sos_user_mechanism')->field('mechanismName')->where('id',$val['mechanism'])->find();
}
$list[$key]['mechanism']=$val['mechanism'] == 0? '男' : $mechanism['mechanismName'];
//所属部门
if($val['department'] != 0){
$department= Db::table('sos_user_department')->field('departmentName')->where('id',$val['department'])->find();
}
$list[$key]['department']=$val['department'] == 0? '男' : $department['departmentName'];
$list[$key]['status']=$type[$val['status']];
$list[$key]['entryTime']=date('Y-m-d H:i:s',$val['entryTime']);
$list[$key]['quitTime']=$val['quitTime'] == ''? '' : date('Y-m-d H:i:s',$val['entryTime']);
}
$result["total"] =count($list);
$result['rows']=$list;
echo json_encode($result);
}
// 添加用户
public function store(Request $request)
{
$data = $request->post();
$validate = new UserValidate();
$err_msg = $validate->scene("add")->check($data);
if ($err_msg) {
return json($this->renderError($validate->getError()));
}
$res = json_decode(curlPost($this->getUrl('add'), $data),true);
if ($res['code'] == self::SUCCESS_CODE) {
return json($this->renderSuccess());
}
return json($res);
}
//修改用户
public function edit(Request $request){
$data = $request->post();
if($data['id']){
$data['uid'] = $data['id'];
}
$validate = new UserValidate();
$err_msg = $validate->scene("update")->check($data);
if ($err_msg) {
return json($this->renderError($validate->getError()));
}
$res = json_decode(curlPost($this->getUrl('edit'), $data),true);
if ($res['code'] == self::SUCCESS_CODE) {
return json($this->renderSuccess());
}
return json($res);
}
//删除用户
public function del(Request $request){
$data = $request->get();
if (empty($data['id']) && $data['id'] !== 0) {
return json($this->renderError("删除失败!"));
}
$res = json_decode(curlPost($this->getUrl("del"),['uid'=>$data['id']]),true);
if ($res['code'] != self::SUCCESS_CODE) {
return json($res);
}
return json($this->renderSuccess());
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\controller;
use app\serviceapi\controller\TurnPrize as TurnPrizeModel;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 抽奖管理
* Class TurnTable
* @package app\products\controller
* Date: 2020/8/25
* Time: 10:00
* @author nyq
*/
class TurnPrize extends BaseController
{
private $appid = 'wx3e41adc018004fd1';
private $appsecrt = 'f072ba0a6dbb24a2f6b504259367ecfc';
//请求地址
//private $api_url = "http://demo8.xiaochakeji.com/serviceapi/prize/";
//查询接口
//本地
//private $api_url = "www.aisigit.com/products/Turn_prize/";
//测试
//private $api_url = "http://demo6.xiaochakeji.com/products/Turn_prize/";
//生产
// private $api_url = "http://hzy.sosyun.com/products/Turn_prize/";
/**
* 函数功能描述 微信分享获取AccessToken
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function getAccessToken() {
//查询数据表里面的值
$data['appid']= $this->appid;
$data['appsecrt']= $this->appsecrt;
$prize_win_model = new TurnPrizeModel();
$info = $prize_win_model->getAccessToken();
//$info = MCurl::instance($this->api_url."getAccessToken")->post($data);
$info = json_decode($info,true);
if(empty($info) || $info['expires_in'] < time()){
//获取token的值
$url_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->appsecrt;
$tmp = $this->curl_get($url_token); //json格式
$obj = json_decode($tmp,true);
if($obj['access_token'] != null){
$data['access_token'] = $obj['access_token'];
$data['expires_in'] = time() + $obj['expires_in'];
if($info){
$data['id'] = $info['id'];
$arr = $prize_win_model->updateAccessToken($data);
//$arr = MCurl::instance($this->api_url."updateAccessToken")->post($data);
}else{
$arr = $prize_win_model->addAccessToken($data);
// $arr = MCurl::instance($this->api_url."addAccessToken")->post($data);
}
return $data;
}else return 'error';
}else return $info;
}
/**
* 函数功能描述 微信分享获取Ticket
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function getTicket(){
$token = $this->getAccessToken();
if(empty($token['jsapi_ticket']) || $token['expires_in'] < time()){
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$token['access_token']."&type=jsapi";
$tmp = $this->curl_get($url); //json格式
$obj = json_decode($tmp,true);
$data['id'] = $token['id'];
$data['jsapi_ticket'] = $obj['jsapi_ticket'];
$prize_win_model = new TurnPrizeModel();
$arr = $prize_win_model->updateAccessToken($data);
//$arr = MCurl::instance($this->api_url."updateAccessToken")->post($data);
return $obj['jsapi_ticket'];
}else{
return $token['jsapi_ticket'];
}
}
/**
* 函数功能描述 微信分享获取sdk
* Date: 2020/8/31
* Time: 10:00
* @author nyq
*/
public function generateSign(Request $request){
$dataurl = $request->param('url');
//echo $dataurl;die;
$url=str_replace('amp;','',$dataurl);
$noncestr = uniqid();
$timestamp = time();
//$url = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
$ticket = $this->getTicket();
if ($ticket) {
$str = 'jsapi_ticket='.$ticket.'&noncestr='.$noncestr.'&timestamp='.$timestamp.'&url='.$url;
//return $str;die;
$signature = sha1($str);
$data['ticket'] = $ticket;
$data['noncestr'] = $noncestr;
$data['timestamp'] = $timestamp;
$data['signature'] = $signature;
$data['appId'] = $this->appid;
$data['link'] = $url;
return $data;
}
}
/**
* 函数功能描述 抽奖用户模拟微信授权 返回 openid
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function getWxCode(Request $request)
{
$data = $request->param();
$code=$data['code'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->appid . "&secret=" . $this->appsecrt . "&code=$code&grant_type=authorization_code";
$r = $this->curl_get($url);
$openid=json_decode($r,true);
return $openid;
}
/**
* 函数功能描述 获取订单信息 / 获取奖品列表接口
* Date: 2020/8/27
* Time: 10:00
* @author nyq
*/
public function prize_list(Request $request)
{
$data = $request->param();
//分页暂未开启,保留.
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 25;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeList($data);
//$res = MCurl::instance($this->api_url."prizeList")->post($data);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
if($val['display'] ==0){
$json[$key]['display']="已发布";
}else{
$json[$key]['display']="未发布";
}
}
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 文件上传
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function uploadFileImgs(){
$files = request()->file('files');
$path = input('path');
if($files){
$imgarr = [];
foreach($files as $file){
$info = $file->validate(['size'=>204800000,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public/web/' . DS . 'prize');
if($info){
$newurl = '/web/prize/'.$info->getSaveName();
$img= str_replace('\\','/',$newurl);
$imgarr[]=$img;
}
}
return json_encode($imgarr);
}else{
echo '没有图片上传';
}
}
/**
* 函数功能描述 删除中奖用户列表
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function del_user()
{
$data = $this->request->post();
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->delUser($data);
//$res = MCurl::instance($this->api_url."delUser")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'删除成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'删除失败'
];
}
return $data;
}
/**
* 函数功能描述 添加奖品
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function prize_add(Request $request)
{
$data = $request->param();
$data['addTime']=time();
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeAdd($data);
//return $res;
// $res = MCurl::instance($this->api_url."prizeAdd")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'修改成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'修改失败'
];
}
return $data;
}
/**
* 函数功能描述 中奖用户列表
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_user_list(Request $request)
{
$data = $request->param();
$page = $data['page'];
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeUserList($data);
//var_dump($res); die;
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
//$res=json_decode($res,true);
$json=$res['rows'];
unset($data['id']);
Cookie::set('data', $data);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
if(isset($val['num']) && $val['num'] !=1 ){
$json[$key]['prizeName']="双击查看";
}
if($val['receive'] ==0){
$json[$key]['receive']="未领取";
}else{
$json[$key]['receive']="已领取";
}
}
$last_names = array_column($json,'addTime');
array_multisort($last_names,SORT_DESC,$json);
//获取当前的条数
// if(isset($data['phone'])&&!empty($data['phone'])) {
// $count = count($json);
// }else{
// $count = MCurl::instance($this->api_url . "prizeUserCount")->post($data);
// $count = json_decode($count, true);
// }
$result["total"] =$res['total'];
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
$data = $this->request->Post();
$data= Cookie::get('data');
$data['to_excel']=1;
$prize_win_model = new TurnPrizeModel();
$json = $prize_win_model->prizeUserList($data);
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
// $json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '用户名')
->setCellValue('B1', '电话')
->setCellValue('C1', '奖品名称')
->setCellValue('D1', '部门')
->setCellValue('E1', '时间');
$rowIndex = 2;
foreach ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['uname'])
->setCellValue('B' . $rowIndex, $v['phone'])
->setCellValue('C' . $rowIndex, $v['prizeName'])
->setCellValue('D' . $rowIndex, $v['source'])
->setCellValue('E' . $rowIndex, $v['addTime']);
$rowIndex++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$filename = '抽奖用户数据表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
/**
* 函数功能描述 重置抽奖次数
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_reset(Request $request)
{
//$data = $request->param();
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeReset();
//$res = MCurl::instance($this->api_url."prizeReset")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'重置成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'重置失败'
];
}
return $data;
}
/**
* 函数功能描述 规则设置 // 获取抽奖规则接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule(Request $request)
{
//$data = $request->param();
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeRule();
//$res = MCurl::instance($this->api_url."prizeRule")->post($data);
$json=json_decode($res,true);
$code="fg5Fu7Is9aHJ5ug5".time();
$json['openid']=$code;
return $json;
// $json=json_encode($res);
// $aa= html_entity_decode($json);
// //数据特殊符号转义
// $aa = htmlspecialchars_decode($aa);
// return $aa;
}
/**
* 函数功能描述 修改规则设置
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule_edit(Request $request)
{
$data = $request->param();
//file_put_contents('aaqq.txt',$data);
//$data['title']=json_encode($data['title'],true);
$data['addTime']=time();
//return $data;
if(isset($data['open']) && $data['open']=="on"){
$data['open']=1;
}else{
$data['open']=0;
}
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeRuleEdit($data);
//$res = MCurl::instance($this->api_url."prizeRuleEdit")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'修改成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'修改失败'
];
}
return $data;
}
/**
* 函数功能描述 获取抽奖规则接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function prize_rule_api(Request $request)
{
$data = $request->param();
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeRuleEdit($data);
// $res = MCurl::instance($this->api_url."prizeRuleEdit")->post($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'重置成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'重置失败'
];
}
return $data;
}
/**
* 函数功能描述 首次进入 合适身份信息
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function sel_prize_member(Request $request)
{
$data = $request->param();
//给我 openID number
//查看当前用户是否存在
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->selPrizeMember($data);
return $res;
// //$res = MCurl::instance($this->api_url."selPrizeMember")->post($data);
// $json=json_decode($res,true);
// return $json;
}
/**
* 函数功能描述 抽奖接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function luck_draw(Request $request)
{
//传递 openID prize_id
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new TurnPrizeModel();
$json = $prize_win_model->luckDraw($data);
//$res = MCurl::instance($this->api_url."luckDraw")->post($data);
//$json=json_decode($res,true);
//传递 openID prize_id
return $json;
}
/**
* 函数功能描述 获取最新的20条中奖列表 / 个人的奖品列表
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function win_list(Request $request)
{
//传递 openID
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->prizeWinList($data);
//$res = MCurl::instance($this->api_url."prizeWinList")->post($data);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
//传递 openID prize_id
return $json;
}
/**
* 函数功能描述 兑奖接口
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function cash_prize(Request $request)
{
//传递 openID
$data = $request->param();
//查看当前用户是否存在
$prize_win_model = new TurnPrizeModel();
$res = $prize_win_model->cashPrize($data);
//$res = MCurl::instance($this->api_url."cashPrize")->post($data);
$json=json_decode($res,true);
if($json==1){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
//传递 openID prize_id
return $data;
}
/**
* 发起GET请求
* @param string $url 请求地址
* @param array $data 请求参数
* @param string $cookiePath 请求所保存的cookie路径
*/
function curl_get($url, $data=[], $cookiePath = '')
{
if(count($data)!=0) {
$url = get_query_url($url, $data);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\model;
use app\common\model\products\ProductSourceRecom as ProductSourceRecomModel;
class ProductSourceRecom extends ProductSourceRecomModel
{
}
\ No newline at end of file
... ...
<?php
namespace app\products\model;
use app\common\model\products\ProductUser as ProductUserModel;
/**
* 功能描述 保险产品用户表
* Class ProductUser
* @package app\products\model
* Date: 2020/7/14
* Time: 9:49
* @author gxd
*/
class ProductUser extends ProductUserModel
{
/**
* 函数功能描述 获取用户是否有推广权限
* Date: 2020/7/14
* Time: 11:15
* @author gxd
*/
public function getPrimByUidAndType($uid,$utype=2,$field="*") {
$res = static::field($field)->where("user_id", $uid)->find();
return $res;
}
}
\ No newline at end of file
... ...
<?php
namespace app\products\model;
use app\common\model\products\Products as ProductsModel;
/**
* 功能描述 保险产品表
* Class Products
* @package app\products\model
* Date: 2020/7/14
* Time: 9:49
* @author gxd
*/
class Products extends ProductsModel
{
}
\ No newline at end of file
... ...