优化代码
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ unpackage
|
||||
node_modules
|
||||
.DS_Store
|
||||
.hbuilderx
|
||||
/runtime/
|
||||
|
||||
299
app/ApiRest.php
299
app/ApiRest.php
@@ -1,23 +1,17 @@
|
||||
<?php
|
||||
declare ( strict_types = 1 );
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app;
|
||||
use app\BaseController;
|
||||
use app\card\model\User;
|
||||
use app\card\model\UserPhone;
|
||||
|
||||
use app\farm\model\Farmer;
|
||||
use app\restaurant\model\Table;
|
||||
use app\shop\model\Cap;
|
||||
use longbingcore\tools\LongbingArr;
|
||||
use Qiniu\Auth;
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Request;
|
||||
use think\Validate;
|
||||
use think\Response;
|
||||
use think\facade\Db;
|
||||
use think\facade\Lang;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
@@ -54,7 +48,7 @@ abstract class ApiRest extends BaseController
|
||||
//唯一app标示
|
||||
public $_uniacid = 1;
|
||||
//定义检查中间件
|
||||
// protected $middleware = [ 'app\middleware\CheckInput' ,'think\middleware\LoadLangPack' ,'app\middleware\GetAuthConfig' ,'app\middleware\AutoStatic','app\middleware\StaticHour'];
|
||||
// protected $middleware = [ 'app\middleware\CheckInput' ,'think\middleware\LoadLangPack' ,'app\middleware\GetAuthConfig' ,'app\middleware\AutoStatic','app\middleware\StaticHour'];
|
||||
|
||||
//获取配置信息
|
||||
protected $_config = [];
|
||||
@@ -70,12 +64,12 @@ abstract class ApiRest extends BaseController
|
||||
// 默认用户头像
|
||||
'avatar' => 'https://retail.xiaochengxucms.com/defaultAvatar.png',
|
||||
// 默认内容图片
|
||||
'image' => 'https://retail.xiaochengxucms.com/lbCardDefaultImage.png',
|
||||
'image' => 'https://retail.xiaochengxucms.com/lbCardDefaultImage.png',
|
||||
);
|
||||
|
||||
protected $_is_weiqin = false ;
|
||||
protected $_is_weiqin = false;
|
||||
|
||||
protected $check_url = "";
|
||||
protected $check_url = "";
|
||||
|
||||
/**
|
||||
* 无需登录的方法,同时也就不需要鉴权了
|
||||
@@ -84,75 +78,83 @@ abstract class ApiRest extends BaseController
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
|
||||
public function __construct ( App $app )
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
|
||||
parent::__construct( $app );
|
||||
|
||||
if(in_array($this->_method,['options','Options','OPTIONS'])){
|
||||
|
||||
echo true;exit;
|
||||
if (in_array($this->_method, ['options', 'Options', 'OPTIONS'])) {
|
||||
echo true;
|
||||
exit;
|
||||
}
|
||||
|
||||
//获取param
|
||||
$this->_param = $this->request->param();
|
||||
//获取body参数
|
||||
$this->_input = json_decode( $this->request->getInput(), true );
|
||||
$this->_input = json_decode($this->request->getInput(), true);
|
||||
//获取头部信息
|
||||
$this->_header = $this->request->header();
|
||||
|
||||
|
||||
$this->is_app = !empty($this->_header['isapp'])?$this->_header['isapp']:0;
|
||||
|
||||
if ( defined( 'IS_WEIQIN' ) )
|
||||
{
|
||||
global $_GPC, $_W;
|
||||
$this->_uniacid = $_W[ 'uniacid' ];
|
||||
if (is_dev()) {
|
||||
// 调试代码
|
||||
$debugUid = $this->_param['debug_uid'] ?? ($this->_input['debug_uid'] ?? null);
|
||||
if ($debugUid !== null) {
|
||||
$this->_user_id = $debugUid;
|
||||
$this->_user = [
|
||||
'id' => $this->_user_id,
|
||||
'uniacid' => $this->_uniacid,
|
||||
'nickname' => 'debug',
|
||||
];
|
||||
$this->noNeedLogin[] = $this->request->action();
|
||||
if (isset($this->_param['debug_uniacid'])) {
|
||||
$this->_uniacid = $this->_param['debug_uniacid'];
|
||||
} elseif (isset($this->_input['debug_uniacid'])) {
|
||||
$this->_uniacid = $this->_input['debug_uniacid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->_param[ 'i' ]))
|
||||
{
|
||||
$this->_uniacid = $this->_param[ 'i' ];
|
||||
|
||||
$this->is_app = !empty($this->_header['isapp']) ? $this->_header['isapp'] : 0;
|
||||
|
||||
if (defined('IS_WEIQIN')) {
|
||||
global $_GPC, $_W;
|
||||
$this->_uniacid = $_W['uniacid'];
|
||||
} else {
|
||||
if (isset($this->_param['i'])) {
|
||||
$this->_uniacid = $this->_param['i'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( defined( 'LONGBING_CARD_UNIACID' ) )
|
||||
{
|
||||
if (defined('LONGBING_CARD_UNIACID')) {
|
||||
|
||||
define( 'LONGBING_CARD_UNIACID', $this->_uniacid );
|
||||
define('LONGBING_CARD_UNIACID', $this->_uniacid);
|
||||
}
|
||||
|
||||
$this->shareChangeData($this->_param);
|
||||
$this->shareChangeData($this->_param);
|
||||
//获取autograph 小程序用户唯一标示
|
||||
if ( isset( $this->_header[ 'autograph' ] ) && $this->_header[ 'autograph' ])
|
||||
{
|
||||
if (isset($this->_header['autograph']) && $this->_header['autograph']) {
|
||||
$this->autograph = $this->_header['autograph'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->match($this->noNeedLogin)){
|
||||
} else {
|
||||
if (!$this->match($this->noNeedLogin)) {
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
$this->errorMsg('need login', 401);
|
||||
|
||||
}
|
||||
}
|
||||
//获取配置信息
|
||||
$this->_config = longbingGetAppConfig($this->_uniacid);
|
||||
//语言
|
||||
if ( isset( $this->_header[ 'lang' ] ) ) $this->_token = $this->_header[ 'lang' ];
|
||||
if (isset($this->_header['lang'])) $this->_token = $this->_header['lang'];
|
||||
|
||||
if(!empty($this->autograph)&&!$this->match($this->noNeedLogin)){
|
||||
if (!empty($this->autograph) && !$this->match($this->noNeedLogin)) {
|
||||
|
||||
$this->_user_id = $this->getUserId();
|
||||
|
||||
$this->_user = $this->getUserInfo();
|
||||
$this->_user = $this->getUserInfo();
|
||||
}
|
||||
|
||||
landNotice($this->_uniacid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +163,8 @@ abstract class ApiRest extends BaseController
|
||||
* @DataTime: 2020-08-21 17:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function shareChangeData($input){
|
||||
public function shareChangeData($input)
|
||||
{
|
||||
|
||||
$arr = [
|
||||
|
||||
@@ -200,11 +203,13 @@ abstract class ApiRest extends BaseController
|
||||
'farm/app/IndexUser/farmerInfo',
|
||||
|
||||
'farm/app/Index/configInfo',
|
||||
|
||||
'farm/app/Index/indexStoreList',
|
||||
];
|
||||
|
||||
if(!empty($input['s'])&&in_array($input['s'],$arr)){
|
||||
if (!empty($input['s']) && in_array($input['s'], $arr)) {
|
||||
|
||||
$input['s'] = trim(strrchr($input['s'], '/'),'/');
|
||||
$input['s'] = trim(strrchr($input['s'], '/'), '/');
|
||||
|
||||
$this->noNeedLogin[] = $input['s'];
|
||||
}
|
||||
@@ -218,18 +223,17 @@ abstract class ApiRest extends BaseController
|
||||
* @DataTime: 2020-07-09 12:00
|
||||
* @功能说明:检测方法传递
|
||||
*/
|
||||
public function match($arr){
|
||||
public function match($arr)
|
||||
{
|
||||
|
||||
|
||||
$arr = is_array($arr) ? $arr : explode(',', $arr);
|
||||
if (!$arr)
|
||||
{
|
||||
if (!$arr) {
|
||||
return FALSE;
|
||||
}
|
||||
$arr = array_map('strtolower', $arr);
|
||||
// 是否存在
|
||||
if (in_array(strtolower($this->request->action()), $arr) || in_array('*', $arr))
|
||||
{
|
||||
if (in_array(strtolower($this->request->action()), $arr) || in_array('*', $arr)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -238,35 +242,36 @@ abstract class ApiRest extends BaseController
|
||||
}
|
||||
|
||||
//返回请求成功的数据
|
||||
public function success ( $data, $code = 200 )
|
||||
public function success($data, $code = 200)
|
||||
{
|
||||
$result[ 'data' ] = LongbingGetWxApiReturnData($data);
|
||||
$result[ 'code' ] = $code;
|
||||
$result[ 'sign' ] = null;
|
||||
$result['data'] = LongbingGetWxApiReturnData($data);
|
||||
$result['code'] = $code;
|
||||
$result['sign'] = null;
|
||||
//复杂的签名
|
||||
// if(isset($this->_user['keys'])){
|
||||
// $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data));
|
||||
// }
|
||||
//简单的签名
|
||||
if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) );
|
||||
return $this->response( $result, 'json', $code );
|
||||
if (!empty($this->_token)) $result['sign'] = createSimpleSign($this->_token, is_string($data) ? $data : json_encode($data));
|
||||
return $this->response($result, 'json', $code);
|
||||
}
|
||||
|
||||
//返回错误数据
|
||||
public function error ( $msg, $code = 400 )
|
||||
public function error($msg, $code = 400)
|
||||
{
|
||||
// $result[ 'error' ] = Lang::get($msg);
|
||||
// $result[ 'code' ] = $code;
|
||||
$result = $this->getErrorData($msg, $code);
|
||||
return $this->response( $result, 'json', 200 );
|
||||
return $this->response($result, 'json', 200);
|
||||
}
|
||||
|
||||
public function getErrorData($msg, $code = 400)
|
||||
{
|
||||
$result[ 'error' ] = Lang::get($msg);
|
||||
$result[ 'code' ] = $code;
|
||||
$result['error'] = Lang::get($msg);
|
||||
$result['code'] = $code;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出返回数据
|
||||
* @access protected
|
||||
@@ -275,9 +280,9 @@ abstract class ApiRest extends BaseController
|
||||
* @param integer $code HTTP状态码
|
||||
* @return Response
|
||||
*/
|
||||
protected function response ( $data, $type = 'json', $code = 200 )
|
||||
protected function response($data, $type = 'json', $code = 200)
|
||||
{
|
||||
return Response::create( $data, $type )->code( $code );
|
||||
return Response::create($data, $type)->code($code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,30 +292,22 @@ abstract class ApiRest extends BaseController
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function _empty ( $method )
|
||||
public function _empty($method)
|
||||
{
|
||||
if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) )
|
||||
{
|
||||
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
||||
// RESTFul方法支持
|
||||
$fun = $method . '_' . $this->method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) )
|
||||
{
|
||||
} elseif ($this->method == $this->restDefaultMethod && method_exists($this, $method . '_' . $this->type)) {
|
||||
$fun = $method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) )
|
||||
{
|
||||
} elseif ($this->type == $this->restDefaultType && method_exists($this, $method . '_' . $this->method)) {
|
||||
$fun = $method . '_' . $this->method;
|
||||
}
|
||||
if ( isset( $fun ) )
|
||||
{
|
||||
return App::invokeMethod( [ $this, $fun ]
|
||||
if (isset($fun)) {
|
||||
return App::invokeMethod([$this, $fun]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// 抛出异常
|
||||
throw new \Exception( 'error action :' . $method );
|
||||
throw new \Exception('error action :' . $method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,25 +318,25 @@ abstract class ApiRest extends BaseController
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
protected function getUserInfo ()
|
||||
protected function getUserInfo()
|
||||
{
|
||||
|
||||
$value = getCache($this->autograph, $this->_uniacid);
|
||||
|
||||
if(empty($value)){
|
||||
if (empty($value)) {
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
$this->errorMsg('need login', 401);
|
||||
}
|
||||
|
||||
if(empty($value['phone'])){
|
||||
if (empty($value['phone'])) {
|
||||
|
||||
// $this->errorMsg('need phone',403);
|
||||
// $this->errorMsg('need phone',403);
|
||||
|
||||
}
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$value['balance'] = $user_model->where(['id'=>$value['id']])->value('balance');
|
||||
$value['balance'] = $user_model->where(['id' => $value['id']])->value('balance');
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -350,37 +347,38 @@ abstract class ApiRest extends BaseController
|
||||
* @DataTime: 2021-03-19 15:22
|
||||
* @功能说明:获取当前的门店信息
|
||||
*/
|
||||
public function getStoreInfo($err=1){
|
||||
public function getStoreInfo($err = 1)
|
||||
{
|
||||
|
||||
$user_id = $this->getUserId();
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$cap_id = $user_model->where(['id'=>$user_id])->value('last_store_id');
|
||||
$cap_id = $user_model->where(['id' => $user_id])->value('last_store_id');
|
||||
|
||||
$cap_info = [];
|
||||
|
||||
if(!empty($cap_id)){
|
||||
if (!empty($cap_id)) {
|
||||
|
||||
$cap_model = new Farmer();
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $cap_id,
|
||||
'id' => $cap_id,
|
||||
|
||||
'status' => 2,
|
||||
'status' => 2,
|
||||
|
||||
'business_status' => 1,
|
||||
|
||||
'type' => 2,
|
||||
'type' => 2,
|
||||
];
|
||||
|
||||
$cap_info = $cap_model->dataInfo($dis);
|
||||
}
|
||||
|
||||
if(empty($cap_info)&&$err==1){
|
||||
if (empty($cap_info) && $err == 1) {
|
||||
|
||||
// $this->errorMsg('请选择店铺',-407);
|
||||
// $this->errorMsg('请选择店铺',-407);
|
||||
|
||||
}
|
||||
|
||||
@@ -389,7 +387,6 @@ abstract class ApiRest extends BaseController
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Purpose: 通过小程序端的用户标示获取用户id
|
||||
*
|
||||
@@ -397,25 +394,24 @@ abstract class ApiRest extends BaseController
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
protected function getUserId ()
|
||||
protected function getUserId()
|
||||
{
|
||||
|
||||
$value = getCache( $this->autograph, $this->_uniacid );
|
||||
$value = getCache($this->autograph, $this->_uniacid);
|
||||
|
||||
if($this->is_app==1){
|
||||
if ($this->is_app == 1) {
|
||||
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$id = $user_model->where(['check'=>1])->value('id');
|
||||
$id = $user_model->where(['check' => 1])->value('id');
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
if ( ($value === false &&!$this->match($this->noNeedLogin)))
|
||||
{
|
||||
if (($value === false && !$this->match($this->noNeedLogin))) {
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
$this->errorMsg('need login', 401);
|
||||
|
||||
}
|
||||
|
||||
@@ -437,68 +433,69 @@ abstract class ApiRest extends BaseController
|
||||
// }
|
||||
|
||||
|
||||
return !empty($value[ 'id' ])?$value[ 'id' ]:0;
|
||||
return !empty($value['id']) ? $value['id'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
|
||||
|
||||
public function payConfig($uniacid = '1', $is_app = 7)
|
||||
{
|
||||
|
||||
public function payConfig ($uniacid = '1',$is_app=7){
|
||||
|
||||
if($is_app==7){
|
||||
if ($is_app == 7) {
|
||||
|
||||
$is_app = $this->is_app;
|
||||
}
|
||||
|
||||
$uniacid_id = !empty($uniacid)?$uniacid:$this->_uniacid;
|
||||
$uniacid_id = !empty($uniacid) ? $uniacid : $this->_uniacid;
|
||||
|
||||
$pay = Db::name('lbfarm_pay_config')->where(['uniacid'=>$uniacid_id])->find();
|
||||
$pay = Db::name('lbfarm_pay_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
|
||||
$config = Db::name( 'lbfarm_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
$config = Db::name('lbfarm_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
if (empty($pay['mch_id']) || empty($pay['pay_key'])) {
|
||||
|
||||
// $this->errorMsg('未配置支付信息');
|
||||
// $this->errorMsg('未配置支付信息');
|
||||
}
|
||||
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
$setting['payment']['merchant_id'] = $pay['mch_id'];
|
||||
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
$setting['payment']['key'] = $pay['pay_key'];
|
||||
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
$setting['payment']['cert_path'] = $pay['cert_path'];
|
||||
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
$setting['payment']['key_path'] = $pay['key_path'];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_appid' ] = $pay[ 'ali_appid' ];
|
||||
$setting['payment']['ali_appid'] = $pay['ali_appid'];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_privatekey' ] = $pay[ 'ali_privatekey' ];
|
||||
$setting['payment']['ali_privatekey'] = $pay['ali_privatekey'];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_publickey' ] = $pay[ 'ali_publickey' ];
|
||||
$setting['payment']['ali_publickey'] = $pay['ali_publickey'];
|
||||
|
||||
if($is_app==0){
|
||||
if ($is_app == 0) {
|
||||
|
||||
$setting[ 'app_id' ] = $config['appid'];
|
||||
$setting['app_id'] = $config['appid'];
|
||||
|
||||
$setting[ 'secret' ] = $config['appsecret'];
|
||||
$setting['secret'] = $config['appsecret'];
|
||||
|
||||
}elseif($is_app==1){
|
||||
} elseif ($is_app == 1) {
|
||||
|
||||
$setting[ 'app_id' ] = $config['app_app_id'];
|
||||
$setting['app_id'] = $config['app_app_id'];
|
||||
|
||||
$setting[ 'secret' ] = $config['app_app_secret'];
|
||||
$setting['secret'] = $config['app_app_secret'];
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$setting[ 'app_id' ] = $config['web_app_id'];
|
||||
$setting['app_id'] = $config['web_app_id'];
|
||||
|
||||
$setting[ 'secret' ] = $config['web_app_secret'];
|
||||
$setting['secret'] = $config['web_app_secret'];
|
||||
|
||||
}
|
||||
|
||||
$setting[ 'is_app' ]= $is_app;
|
||||
$setting['is_app'] = $is_app;
|
||||
|
||||
return $setting;
|
||||
}
|
||||
@@ -511,35 +508,32 @@ abstract class ApiRest extends BaseController
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
|
||||
public function getFormId ( $to_uid )
|
||||
public function getFormId($to_uid)
|
||||
{
|
||||
return [];
|
||||
// 七天前开始的的时间戳
|
||||
// $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 6, date( 'Y' ) );
|
||||
$beginTime = strtotime(date('Y-m-d',time()))-86400*6;
|
||||
$formId = Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'user_id' => $to_uid ] )
|
||||
->order( 'id desc' )
|
||||
$beginTime = strtotime(date('Y-m-d', time())) - 86400 * 6;
|
||||
$formId = Db::name('longbing_card_formId')
|
||||
->where(['user_id' => $to_uid])
|
||||
->order('id desc')
|
||||
->select();
|
||||
if ( empty( $formId ) )
|
||||
{
|
||||
if (empty($formId)) {
|
||||
return false;
|
||||
}
|
||||
if ( $formId[ 0 ][ 'create_time' ] < $beginTime )
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
if ($formId[0]['create_time'] < $beginTime) {
|
||||
Db::name('longbing_card_formId')
|
||||
->where(['id' => $formId[0]['id']])
|
||||
->delete();
|
||||
$this->getFormId( $to_uid );
|
||||
}
|
||||
else
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
$this->getFormId($to_uid);
|
||||
} else {
|
||||
Db::name('longbing_card_formId')
|
||||
->where(['id' => $formId[0]['id']])
|
||||
->delete();
|
||||
return $formId[ 0 ][ 'formId' ];
|
||||
return $formId[0]['formId'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-12 20:37
|
||||
@@ -547,9 +541,10 @@ abstract class ApiRest extends BaseController
|
||||
* @return void
|
||||
* descption:直接抛出异常
|
||||
*/
|
||||
protected function errorMsg($msg = '',$code = 400){
|
||||
protected function errorMsg($msg = '', $code = 400)
|
||||
{
|
||||
$msg = Lang::get($msg);
|
||||
$this->results($msg,$code);
|
||||
$this->results($msg, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -563,7 +558,7 @@ abstract class ApiRest extends BaseController
|
||||
*/
|
||||
protected function results($msg, $code, array $header = [])
|
||||
{
|
||||
$result = [
|
||||
$result = [
|
||||
'error' => $msg,
|
||||
'code' => $code,
|
||||
];
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace app\farm\controller;
|
||||
|
||||
use app\ApiRest;
|
||||
|
||||
|
||||
@@ -21,7 +23,6 @@ use app\farm\model\WelfareColumn;
|
||||
use app\massage\model\Config;
|
||||
|
||||
|
||||
|
||||
use app\farm\model\Address;
|
||||
|
||||
use app\farm\model\User;
|
||||
@@ -30,6 +31,9 @@ use app\publics\model\TmplConfig;
|
||||
|
||||
use longbingcore\wxcore\YsCloudApi;
|
||||
use think\App;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\Request;
|
||||
|
||||
@@ -40,7 +44,8 @@ class Index extends ApiRest
|
||||
protected $model;
|
||||
|
||||
|
||||
public function __construct(App $app) {
|
||||
public function __construct(App $app)
|
||||
{
|
||||
|
||||
parent::__construct($app);
|
||||
|
||||
@@ -49,13 +54,59 @@ class Index extends ApiRest
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 农场列表
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DataNotFoundException
|
||||
*/
|
||||
public function indexStoreList()
|
||||
{
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid,
|
||||
|
||||
'status' => 2,
|
||||
|
||||
'type' => 2,
|
||||
|
||||
'business_status' => 1
|
||||
];
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
|
||||
$lat = !empty($input['lat']) ? $input['lat'] : 0;
|
||||
|
||||
$lng = !empty($input['lng']) ? $input['lng'] : 0;
|
||||
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lng . '- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS(' . $lat . ' * PI()/180)*POW(SIN(PI()*(' . $lat . '- lat)/360),2))))*1000 as distance';
|
||||
//门店列表
|
||||
$store = $farmer_model->where($dis)->field(['*', $alh])->order('distance,id desc')->limit(10)->select()->toArray();
|
||||
|
||||
if (!empty($store)) {
|
||||
|
||||
foreach ($store as &$v) {
|
||||
|
||||
$v['distance'] = getDistances($v['lng'], $v['lat'], $lng, $lat);
|
||||
|
||||
$v['distance'] = $farmer_model->getDistanceAttr($v['distance']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->success($store);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-02 16:58
|
||||
* @功能说明:首页
|
||||
*/
|
||||
public function index(){
|
||||
public function index()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -72,13 +123,13 @@ class Index extends ApiRest
|
||||
|
||||
$banner_model = new Banner();
|
||||
|
||||
foreach ($arr as $k=>$v){
|
||||
foreach ($arr as $k => $v) {
|
||||
|
||||
$dis = [
|
||||
|
||||
'type' => $k,
|
||||
'type' => $k,
|
||||
|
||||
'status' => 1,
|
||||
'status' => 1,
|
||||
|
||||
'uniacid' => $this->_uniacid
|
||||
];
|
||||
@@ -86,44 +137,44 @@ class Index extends ApiRest
|
||||
$data['banner'][$v] = $banner_model->where($dis)->order('top desc,id desc')->select()->toArray();
|
||||
}
|
||||
|
||||
$where[] = ['uniacid','=',$this->_uniacid];
|
||||
$where[] = ['uniacid', '=', $this->_uniacid];
|
||||
|
||||
$where[] = ['status','=',1];
|
||||
$where[] = ['status', '=', 1];
|
||||
|
||||
$where[] = ['type','=',0];
|
||||
$where[] = ['type', '=', 0];
|
||||
|
||||
$us_model = new AboutUs();
|
||||
|
||||
$about = $us_model->dataInfo($where);
|
||||
//收否有关于我们
|
||||
$data['about_us'] = !empty($about)?1:0;
|
||||
$data['about_us'] = !empty($about) ? 1 : 0;
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid,
|
||||
|
||||
'status' => 2,
|
||||
'status' => 2,
|
||||
|
||||
'type' => 2,
|
||||
'type' => 2,
|
||||
|
||||
'business_status' => 1
|
||||
];
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
|
||||
$lat = !empty($input['lat'])?$input['lat']:0;
|
||||
$lat = !empty($input['lat']) ? $input['lat'] : 0;
|
||||
|
||||
$lng = !empty($input['lng'])?$input['lng']:0;
|
||||
$lng = !empty($input['lng']) ? $input['lng'] : 0;
|
||||
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*('.$lng.'- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS('.$lat.' * PI()/180)*POW(SIN(PI()*('.$lat.'- lat)/360),2))))*1000 as distance';
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lng . '- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS(' . $lat . ' * PI()/180)*POW(SIN(PI()*(' . $lat . '- lat)/360),2))))*1000 as distance';
|
||||
//门店列表
|
||||
$store = $farmer_model->where($dis)->field(['*',$alh])->order('distance,id desc')->limit(3)->select()->toArray();
|
||||
$store = $farmer_model->where($dis)->field(['*', $alh])->order('distance,id desc')->limit(3)->select()->toArray();
|
||||
|
||||
if(!empty($store)){
|
||||
if (!empty($store)) {
|
||||
|
||||
foreach ($store as &$v){
|
||||
foreach ($store as &$v) {
|
||||
|
||||
$v['distance'] = getDistances($v['lng'],$v['lat'],$lng,$lat);
|
||||
$v['distance'] = getDistances($v['lng'], $v['lat'], $lng, $lat);
|
||||
|
||||
$v['distance'] = $farmer_model->getDistanceAttr($v['distance']);
|
||||
|
||||
@@ -142,15 +193,15 @@ class Index extends ApiRest
|
||||
|
||||
$welfare_model = new WelfareColumn();
|
||||
|
||||
foreach ($arr as $k=>$value){
|
||||
foreach ($arr as $k => $value) {
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid,
|
||||
|
||||
'status' => 1,
|
||||
'status' => 1,
|
||||
|
||||
'type' => $k
|
||||
'type' => $k
|
||||
];
|
||||
|
||||
$data[$value] = $welfare_model->where($dis)->order('top desc,id desc')->limit(5)->select()->toArray();
|
||||
@@ -165,7 +216,7 @@ class Index extends ApiRest
|
||||
|
||||
'index_show' => 1,
|
||||
|
||||
'status' => 1
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$data['hot_goods'] = $goods_model->where($dis)->order('top desc,id desc')->limit(3)->select()->toArray();
|
||||
@@ -174,22 +225,14 @@ class Index extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-18 16:41
|
||||
* @功能说明:获取天气
|
||||
*/
|
||||
public function weather(){
|
||||
|
||||
public function weather()
|
||||
{
|
||||
$input = $this->_param;
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid
|
||||
@@ -199,33 +242,33 @@ class Index extends ApiRest
|
||||
|
||||
$config = $config_model->dataInfo($dis);
|
||||
|
||||
$url = 'https://apis.map.qq.com/ws/geocoder/v1/?location='.$input['lat'].','.$input['lng'];
|
||||
$url = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $input['lat'] . ',' . $input['lng'];
|
||||
|
||||
$url = $url.'&key='.$config['map_secret'];
|
||||
$url = $url . '&key=' . $config['map_secret'];
|
||||
|
||||
$location = longbingCurl($url,[]);
|
||||
$location = longbingCurl($url, []);
|
||||
|
||||
$location = json_decode($location,true);
|
||||
$location = json_decode($location, true);
|
||||
|
||||
$data['weather'] = [];
|
||||
|
||||
if(!empty($location['result']['address_component'])){
|
||||
if (!empty($location['result']['address_component'])) {
|
||||
|
||||
$location = $location['result']['address_component'];
|
||||
|
||||
if(!empty($location['province'])){
|
||||
if (!empty($location['province'])) {
|
||||
|
||||
$province = $location['province'];
|
||||
|
||||
$city = $location['city'];
|
||||
$city = $location['city'];
|
||||
|
||||
$county = $location['district'];
|
||||
$county = $location['district'];
|
||||
|
||||
$url = 'https://wis.qq.com/weather/common?source=pc&weather_type=observe|forecast_24h|air&province='.$province.'&city='.$city.'&county='.$county;
|
||||
$url = 'https://wis.qq.com/weather/common?source=pc&weather_type=observe|forecast_24h|air&province=' . $province . '&city=' . $city . '&county=' . $county;
|
||||
|
||||
$weather = file_get_contents($url);
|
||||
|
||||
$weather = @json_decode($weather,true);
|
||||
$weather = @json_decode($weather, true);
|
||||
//天气
|
||||
$data['weather'] = $weather;
|
||||
}
|
||||
@@ -242,10 +285,9 @@ class Index extends ApiRest
|
||||
* @DataTime: 2021-03-23 14:16
|
||||
* @功能说明:获取配置信息
|
||||
*/
|
||||
public function configInfo(){
|
||||
|
||||
public function configInfo()
|
||||
{
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid
|
||||
];
|
||||
|
||||
@@ -258,21 +300,21 @@ class Index extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 15:21
|
||||
* @功能说明:
|
||||
*/
|
||||
public function farmerSelectList(){
|
||||
public function farmerSelectList()
|
||||
{
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $this->_uniacid,
|
||||
|
||||
'status' => 2,
|
||||
'status' => 2,
|
||||
|
||||
'type' => 1
|
||||
'type' => 1
|
||||
];
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
@@ -289,34 +331,35 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-01-07 14:35
|
||||
* @功能说明:农场列表
|
||||
*/
|
||||
public function farmerList(){
|
||||
public function farmerList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['uniacid', '=', $this->_uniacid];
|
||||
|
||||
$dis[] = ['status','=',2];
|
||||
$dis[] = ['status', '=', 2];
|
||||
|
||||
$dis[] = ['type','=',1];
|
||||
$dis[] = ['type', '=', 1];
|
||||
|
||||
if(!empty($input['title'])){
|
||||
if (!empty($input['title'])) {
|
||||
|
||||
$dis[] = ['title','like','%'.$input['title'].'%'];
|
||||
$dis[] = ['title', 'like', '%' . $input['title'] . '%'];
|
||||
|
||||
}
|
||||
|
||||
$sort = !empty($input['sort'])?$input['sort']:2;
|
||||
$sort = !empty($input['sort']) ? $input['sort'] : 2;
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
|
||||
$lat = !empty($input['lat'])?$input['lat']:0;
|
||||
$lat = !empty($input['lat']) ? $input['lat'] : 0;
|
||||
|
||||
$lng = !empty($input['lng'])?$input['lng']:0;
|
||||
$lng = !empty($input['lng']) ? $input['lng'] : 0;
|
||||
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*('.$lng.'- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS('.$lat.' * PI()/180)*POW(SIN(PI()*('.$lat.'- lat)/360),2))))*1000 as distance';
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lng . '- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS(' . $lat . ' * PI()/180)*POW(SIN(PI()*(' . $lat . '- lat)/360),2))))*1000 as distance';
|
||||
|
||||
switch ($sort){
|
||||
switch ($sort) {
|
||||
|
||||
case 1:
|
||||
|
||||
@@ -337,15 +380,15 @@ class Index extends ApiRest
|
||||
break;
|
||||
}
|
||||
|
||||
$data = $farmer_model->where($dis)->field(['*',$alh])->order($top)->paginate(10)->toArray();
|
||||
$data = $farmer_model->where($dis)->field(['*', $alh])->order($top)->paginate(10)->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
foreach ($data['data'] as &$v) {
|
||||
|
||||
$dis = [
|
||||
|
||||
'type' => 2,
|
||||
'type' => 2,
|
||||
|
||||
'user_id' => $v['user_id'],
|
||||
|
||||
@@ -368,7 +411,8 @@ class Index extends ApiRest
|
||||
* @功能说明:农场详情
|
||||
*
|
||||
*/
|
||||
public function farmerInfo(){
|
||||
public function farmerInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -381,11 +425,11 @@ class Index extends ApiRest
|
||||
|
||||
$data = $farmer_model->dataInfo($dis);
|
||||
|
||||
$farmer_model->dataUpdate($dis,['iv'=>$data['iv']+1]);
|
||||
$farmer_model->dataUpdate($dis, ['iv' => $data['iv'] + 1]);
|
||||
|
||||
$dis = [
|
||||
|
||||
'type' => 2,
|
||||
'type' => 2,
|
||||
|
||||
'user_id' => $data['user_id'],
|
||||
|
||||
@@ -404,15 +448,16 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-01-06 15:21
|
||||
* @功能说明:文章详情
|
||||
*/
|
||||
public function articleInfo(){
|
||||
public function articleInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$article_model = new Article();
|
||||
|
||||
$data = $article_model->dataInfo(['id'=>$input['article_id']]);
|
||||
$data = $article_model->dataInfo(['id' => $input['article_id']]);
|
||||
|
||||
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||||
$data['create_time'] = date('Y-m-d H:i:s', $data['create_time']);
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
@@ -425,19 +470,20 @@ class Index extends ApiRest
|
||||
* @DataTime: 2021-12-30 11:51
|
||||
* @功能说明:关于我们列表
|
||||
*/
|
||||
public function aboutUsList(){
|
||||
public function aboutUsList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['uniacid', '=', $this->_uniacid];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
$dis[] = ['status', '=', 1];
|
||||
|
||||
$dis[] = ['type','=',0];
|
||||
$dis[] = ['type', '=', 0];
|
||||
|
||||
if(!empty($input['title'])){
|
||||
if (!empty($input['title'])) {
|
||||
|
||||
$dis[] = ['title','like','%'.$input['title'].'%'];
|
||||
$dis[] = ['title', 'like', '%' . $input['title'] . '%'];
|
||||
}
|
||||
|
||||
$us_model = new AboutUs();
|
||||
@@ -454,15 +500,16 @@ class Index extends ApiRest
|
||||
* @DataTime: 2021-11-08 13:23
|
||||
* @功能说明:我们列表详情
|
||||
*/
|
||||
public function aboutUsInfoType(){
|
||||
public function aboutUsInfoType()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$input['type'] = !empty($input['type'])?$input['type']:0;
|
||||
$input['type'] = !empty($input['type']) ? $input['type'] : 0;
|
||||
|
||||
$dis = [
|
||||
|
||||
'type'=> $input['type'],
|
||||
'type' => $input['type'],
|
||||
|
||||
'uniacid' => $this->_uniacid
|
||||
];
|
||||
@@ -471,9 +518,9 @@ class Index extends ApiRest
|
||||
|
||||
$res = $us_model->dataInfo($dis);
|
||||
|
||||
if(!empty($input['type'])&&empty($res)){
|
||||
if (!empty($input['type']) && empty($res)) {
|
||||
|
||||
$title = $input['type']==1?'动物认养协议':'土地租赁协议';
|
||||
$title = $input['type'] == 1 ? '动物认养协议' : '土地租赁协议';
|
||||
|
||||
$dis['title'] = $title;
|
||||
|
||||
@@ -491,7 +538,8 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-09 17:07
|
||||
* @功能说明:添加评价
|
||||
*/
|
||||
public function evaluateAdd(){
|
||||
public function evaluateAdd()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
@@ -501,12 +549,12 @@ class Index extends ApiRest
|
||||
|
||||
'order_id' => $input['order_id'],
|
||||
|
||||
'type' => $input['type']
|
||||
'type' => $input['type']
|
||||
];
|
||||
|
||||
$find = $eva_model->where($dis)->where('status','>',-1)->find();
|
||||
$find = $eva_model->where($dis)->where('status', '>', -1)->find();
|
||||
|
||||
if(!empty($find)){
|
||||
if (!empty($find)) {
|
||||
|
||||
$this->errorMsg('你已经评价过该订单了');
|
||||
}
|
||||
@@ -517,19 +565,19 @@ class Index extends ApiRest
|
||||
|
||||
'user_id' => $this->getUserId(),
|
||||
|
||||
'order_id'=> $input['order_id'],
|
||||
'order_id' => $input['order_id'],
|
||||
|
||||
'star' => $input['star'],
|
||||
'star' => $input['star'],
|
||||
|
||||
'type' => $input['type'],
|
||||
'type' => $input['type'],
|
||||
|
||||
'order_code'=> $input['order_code'],
|
||||
'order_code' => $input['order_code'],
|
||||
|
||||
'text' => $input['text'],
|
||||
'text' => $input['text'],
|
||||
|
||||
'imgs' => !empty($input['imgs'])?implode(',',$input['imgs']):'',
|
||||
'imgs' => !empty($input['imgs']) ? implode(',', $input['imgs']) : '',
|
||||
|
||||
'farmer_id' => !empty($input['farmer_id'])?$input['farmer_id']:0,
|
||||
'farmer_id' => !empty($input['farmer_id']) ? $input['farmer_id'] : 0,
|
||||
|
||||
];
|
||||
|
||||
@@ -547,33 +595,34 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-09 17:17
|
||||
* @功能说明:用户评列表
|
||||
*/
|
||||
public function userEvaluateList(){
|
||||
public function userEvaluateList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$eva_model = new Evaluate();
|
||||
|
||||
$dis[] = ['user_id','=',$this->getUserId()];
|
||||
$dis[] = ['user_id', '=', $this->getUserId()];
|
||||
|
||||
$dis[] = ['status','>',-1];
|
||||
$dis[] = ['status', '>', -1];
|
||||
|
||||
if(!empty($input['type'])){
|
||||
if (!empty($input['type'])) {
|
||||
|
||||
$dis[] = ['type','=',$input['type']];
|
||||
$dis[] = ['type', '=', $input['type']];
|
||||
|
||||
}
|
||||
|
||||
$data = $eva_model->dataList($dis);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
foreach ($data['data'] as &$v) {
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
$v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
|
||||
|
||||
if(!empty($v['order_info']['end_time'])){
|
||||
if (!empty($v['order_info']['end_time'])) {
|
||||
|
||||
$v['order_info']['end_time'] = date('Y-m-d H:i:s',$v['order_info']['end_time']);
|
||||
$v['order_info']['end_time'] = date('Y-m-d H:i:s', $v['order_info']['end_time']);
|
||||
|
||||
}
|
||||
|
||||
@@ -591,13 +640,14 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-09 17:21
|
||||
* @功能说明:评价详情
|
||||
*/
|
||||
public function evaluateInfo(){
|
||||
public function evaluateInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$eva_model = new Evaluate();
|
||||
|
||||
$dis =[
|
||||
$dis = [
|
||||
|
||||
'id' => $input['id']
|
||||
];
|
||||
@@ -614,22 +664,23 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-09 17:21
|
||||
* @功能说明:评价详情
|
||||
*/
|
||||
public function evaluateUpdate(){
|
||||
public function evaluateUpdate()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
$eva_model = new Evaluate();
|
||||
|
||||
$dis =[
|
||||
$dis = [
|
||||
|
||||
'id' => $input['id']
|
||||
];
|
||||
|
||||
$info = $eva_model->dataInfo($dis);
|
||||
|
||||
$data = $eva_model->dataUpdate($dis,$input);
|
||||
$data = $eva_model->dataUpdate($dis, $input);
|
||||
|
||||
if(!empty($input['status'])&&$input['status']==-1){
|
||||
if (!empty($input['status']) && $input['status'] == -1) {
|
||||
//修改农场主的评分
|
||||
$res = $eva_model->updateFarmerStar($info['farmer_id']);
|
||||
}
|
||||
@@ -644,7 +695,8 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-10 17:23
|
||||
* @功能说明:待评价订单
|
||||
*/
|
||||
public function noEvaluateOrderList(){
|
||||
public function noEvaluateOrderList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -656,39 +708,39 @@ class Index extends ApiRest
|
||||
|
||||
'user_id' => $this->getUserId(),
|
||||
|
||||
'type' => $input['type']
|
||||
'type' => $input['type']
|
||||
];
|
||||
|
||||
$order_id = $eva_model->where($where)->where('status','>',-1)->column('order_id');
|
||||
$order_id = $eva_model->where($where)->where('status', '>', -1)->column('order_id');
|
||||
|
||||
$dis[] = ['user_id','=',$this->getUserId()];
|
||||
$dis[] = ['user_id', '=', $this->getUserId()];
|
||||
|
||||
if($input['type']==2){
|
||||
if ($input['type'] == 2) {
|
||||
|
||||
$dis[] = ['pay_type','>',1];
|
||||
$dis[] = ['pay_type', '>', 1];
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$dis[] = ['pay_type','=',7];
|
||||
$dis[] = ['pay_type', '=', 7];
|
||||
}
|
||||
|
||||
$dis[] = ['id','not in',$order_id];
|
||||
$dis[] = ['id', 'not in', $order_id];
|
||||
|
||||
$data = $model->dataList($dis,10);
|
||||
$data = $model->dataList($dis, 10);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
foreach ($data['data'] as &$v) {
|
||||
|
||||
$farmer_id = !empty($v['farmer_id'])?$v['farmer_id']:0;
|
||||
$farmer_id = !empty($v['farmer_id']) ? $v['farmer_id'] : 0;
|
||||
|
||||
$v['farmer_info'] = $farmer_model->dataInfo(['id'=>$farmer_id],'title');
|
||||
$v['farmer_info'] = $farmer_model->dataInfo(['id' => $farmer_id], 'title');
|
||||
|
||||
if(!empty($v['end_time'])){
|
||||
if (!empty($v['end_time'])) {
|
||||
|
||||
$v['end_time'] = date('Y-m-d H:i:s',$v['end_time']);
|
||||
$v['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -705,13 +757,14 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-02-11 10:11
|
||||
* @功能说明:根据type获取对应物品的评价
|
||||
*/
|
||||
public function goodsEvaluateList(){
|
||||
public function goodsEvaluateList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$eva_model = new Evaluate();
|
||||
|
||||
$data = $eva_model->goodsEvaluateList($input['goods_id'],$input['type'],$input['is_goods']);
|
||||
$data = $eva_model->goodsEvaluateList($input['goods_id'], $input['type'], $input['is_goods']);
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
@@ -723,11 +776,12 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-03-09 16:50
|
||||
* @功能说明:模版列表
|
||||
*/
|
||||
public function tmpList(){
|
||||
public function tmpList()
|
||||
{
|
||||
//模版消息model
|
||||
$tmpl_model = new TmplConfig();
|
||||
//获取模版
|
||||
$tmpl = $tmpl_model->where(['uniacid'=>$this->_uniacid])->select()->toArray();
|
||||
$tmpl = $tmpl_model->where(['uniacid' => $this->_uniacid])->select()->toArray();
|
||||
|
||||
return $this->success($tmpl);
|
||||
|
||||
@@ -739,45 +793,46 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-04-11 15:56
|
||||
* @功能说明:监控列表
|
||||
*/
|
||||
public function monitorList(){
|
||||
public function monitorList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['a.uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['a.uniacid', '=', $this->_uniacid];
|
||||
|
||||
if(!empty($input['farmer_id'])){
|
||||
if (!empty($input['farmer_id'])) {
|
||||
|
||||
$dis[] = ['a.farmer_id','=',$input['farmer_id']];
|
||||
$dis[] = ['a.farmer_id', '=', $input['farmer_id']];
|
||||
|
||||
}else{
|
||||
} else {
|
||||
//我的菜地
|
||||
$land_model = new LandOrder();
|
||||
|
||||
$claim_model= new ClaimOrder();
|
||||
$claim_model = new ClaimOrder();
|
||||
|
||||
$monitor_text_model = new MonitorText();
|
||||
|
||||
$land_text_model = new LandText();
|
||||
|
||||
$land_id = $land_model->where(['user_id'=>$this->getUserId()])->where('pay_type','>',1)->column('land_id');
|
||||
$land_id = $land_model->where(['user_id' => $this->getUserId()])->where('pay_type', '>', 1)->column('land_id');
|
||||
|
||||
$obj_id = $land_text_model->where('land_id','in',$land_id)->where(['type'=>4])->column('obj_id');
|
||||
$obj_id = $land_text_model->where('land_id', 'in', $land_id)->where(['type' => 4])->column('obj_id');
|
||||
|
||||
$claim_id= $claim_model->where(['user_id'=>$this->getUserId()])->where('pay_type','>',1)->column('goods_id');
|
||||
$claim_id = $claim_model->where(['user_id' => $this->getUserId()])->where('pay_type', '>', 1)->column('goods_id');
|
||||
|
||||
$obj_id_v2 = $monitor_text_model->where('obj_id','in',$claim_id)->where(['type'=>2])->column('monitor_id');
|
||||
$obj_id_v2 = $monitor_text_model->where('obj_id', 'in', $claim_id)->where(['type' => 2])->column('monitor_id');
|
||||
|
||||
$monitor_id = array_merge($obj_id,$obj_id_v2);
|
||||
$monitor_id = array_merge($obj_id, $obj_id_v2);
|
||||
|
||||
$dis[] = ['a.id','in',$monitor_id];
|
||||
$dis[] = ['a.id', 'in', $monitor_id];
|
||||
|
||||
}
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
$dis[] = ['a.status', '=', 1];
|
||||
|
||||
if(!empty($input['title'])){
|
||||
if (!empty($input['title'])) {
|
||||
|
||||
$dis[] = ['a.title','like','%'.$input['title'].'%'];
|
||||
$dis[] = ['a.title', 'like', '%' . $input['title'] . '%'];
|
||||
|
||||
}
|
||||
|
||||
@@ -795,7 +850,8 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-04-11 16:31
|
||||
* @功能说明:获取监控地址
|
||||
*/
|
||||
public function getMonitorInfo(){
|
||||
public function getMonitorInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -817,7 +873,8 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-04-12 11:01
|
||||
* @功能说明:获取萤石云token
|
||||
*/
|
||||
public function getYsToken(){
|
||||
public function getYsToken()
|
||||
{
|
||||
|
||||
$api = new YsCloudApi($this->_uniacid);
|
||||
|
||||
@@ -833,7 +890,8 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-04-12 11:02
|
||||
* @功能说明:旋转摄像头
|
||||
*/
|
||||
public function ysStartTurn(){
|
||||
public function ysStartTurn()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -841,22 +899,22 @@ class Index extends ApiRest
|
||||
|
||||
$api = new YsCloudApi($this->_uniacid);
|
||||
|
||||
$monitor = $monitor_model->dataInfo(['id'=>$input['id']]);
|
||||
$monitor = $monitor_model->dataInfo(['id' => $input['id']]);
|
||||
|
||||
$res = $api->startTurn($monitor['deviceSerial'],$input['direction'],$monitor['channelNo']);
|
||||
$res = $api->startTurn($monitor['deviceSerial'], $input['direction'], $monitor['channelNo']);
|
||||
|
||||
return $this->success($res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-12 11:02
|
||||
* @功能说明:停止旋转摄像头
|
||||
*/
|
||||
public function ysStopTurn(){
|
||||
public function ysStopTurn()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -864,25 +922,24 @@ class Index extends ApiRest
|
||||
|
||||
$api = new YsCloudApi($this->_uniacid);
|
||||
|
||||
$monitor = $monitor_model->dataInfo(['id'=>$input['id']]);
|
||||
$monitor = $monitor_model->dataInfo(['id' => $input['id']]);
|
||||
|
||||
$direction = !empty($input['direction'])?$input['direction']:0;
|
||||
$direction = !empty($input['direction']) ? $input['direction'] : 0;
|
||||
|
||||
$res = $api->stopTurn($monitor['deviceSerial'],$direction,$monitor['channelNo']);
|
||||
$res = $api->stopTurn($monitor['deviceSerial'], $direction, $monitor['channelNo']);
|
||||
|
||||
return $this->success($res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function haveStore()
|
||||
{
|
||||
|
||||
|
||||
$data = $this->getStoreInfo(2);
|
||||
|
||||
$res = !empty($data)?true:false;
|
||||
$res = !empty($data) ? true : false;
|
||||
|
||||
return $this->success($res);
|
||||
|
||||
@@ -895,27 +952,28 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-07-22 17:34
|
||||
* @功能说明:公益列表
|
||||
*/
|
||||
public function welfareColumnList(){
|
||||
public function welfareColumnList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['uniacid', '=', $this->_uniacid];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
$dis[] = ['status', '=', 1];
|
||||
|
||||
$type = !empty($input['type'])?$input['type']:1;
|
||||
$type = !empty($input['type']) ? $input['type'] : 1;
|
||||
|
||||
$dis[] = ['type','=',$type];
|
||||
$dis[] = ['type', '=', $type];
|
||||
|
||||
$model = new WelfareColumn();
|
||||
|
||||
if(!empty($input['title'])){
|
||||
if (!empty($input['title'])) {
|
||||
|
||||
$dis[] = ['title','like','%'.$input['title'].'%'];
|
||||
$dis[] = ['title', 'like', '%' . $input['title'] . '%'];
|
||||
|
||||
}
|
||||
|
||||
$data = $model->dataList($dis,10,'id,title,cover,create_time');
|
||||
$data = $model->dataList($dis, 10, 'id,title,cover,create_time');
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
@@ -926,13 +984,14 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-07-22 17:34
|
||||
* @功能说明:公益列表
|
||||
*/
|
||||
public function welfareColumnInfo(){
|
||||
public function welfareColumnInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $input['id'],
|
||||
'id' => $input['id'],
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
@@ -946,52 +1005,51 @@ class Index extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-06-15 16:29
|
||||
* @功能说明:优惠券
|
||||
*/
|
||||
public function couponList(){
|
||||
public function couponList()
|
||||
{
|
||||
|
||||
$coupon_record_model = new CouponRecord();
|
||||
|
||||
$coupon_model = new Coupon();
|
||||
|
||||
if(empty($this->getUserId())){
|
||||
if (empty($this->getUserId())) {
|
||||
|
||||
return $this->success([]);
|
||||
|
||||
}
|
||||
|
||||
$have_get = $coupon_record_model->where(['user_id'=>$this->getUserId()])->column('coupon_id');
|
||||
$have_get = $coupon_record_model->where(['user_id' => $this->getUserId()])->column('coupon_id');
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['uniacid', '=', $this->_uniacid];
|
||||
|
||||
$dis[] = ['send_type','=',2];
|
||||
$dis[] = ['send_type', '=', 2];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
$dis[] = ['status', '=', 1];
|
||||
|
||||
$dis[] = ['stock','>',0];
|
||||
$dis[] = ['stock', '>', 0];
|
||||
|
||||
$dis[] = ['id','not in',$have_get];
|
||||
$dis[] = ['id', 'not in', $have_get];
|
||||
|
||||
$where = [];
|
||||
|
||||
$where[] = ['time_limit','=',2];
|
||||
$where[] = ['time_limit', '=', 2];
|
||||
|
||||
$where[] = ['end_time','>',time()];
|
||||
$where[] = ['end_time', '>', time()];
|
||||
|
||||
$data = $coupon_model->where($dis)->where(function ($query) use ($where){
|
||||
$data = $coupon_model->where($dis)->where(function ($query) use ($where) {
|
||||
$query->whereOr($where);
|
||||
})->paginate(10)->toArray();
|
||||
|
||||
if(!empty($coupon['data'])){
|
||||
if (!empty($coupon['data'])) {
|
||||
|
||||
foreach ($coupon['data'] as &$v){
|
||||
foreach ($coupon['data'] as &$v) {
|
||||
|
||||
$v['start_time'] = date('Y.m.d H:i',$v['start_time']).' - '.date('Y.m.d H:i',$v['end_time']);
|
||||
$v['start_time'] = date('Y.m.d H:i', $v['start_time']) . ' - ' . date('Y.m.d H:i', $v['end_time']);
|
||||
|
||||
}
|
||||
|
||||
@@ -1007,15 +1065,16 @@ class Index extends ApiRest
|
||||
* @DataTime: 2022-06-15 22:49
|
||||
* @功能说明:用户获取卡券
|
||||
*/
|
||||
public function userGetCoupon(){
|
||||
public function userGetCoupon()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
$coupon_record_model = new CouponRecord();
|
||||
|
||||
$res = $coupon_record_model->recordAdd($input['coupon_id'],$this->getUserId(),1,1);
|
||||
$res = $coupon_record_model->recordAdd($input['coupon_id'], $this->getUserId(), 1, 1);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
if (!empty($res['code'])) {
|
||||
|
||||
$this->errorMsg($res['msg']);
|
||||
}
|
||||
@@ -1024,6 +1083,4 @@ class Index extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace app\farm\controller;
|
||||
|
||||
use app\ApiRest;
|
||||
|
||||
use app\farm\model\Farmer;
|
||||
@@ -24,7 +26,6 @@ use think\App;
|
||||
use think\Request;
|
||||
|
||||
|
||||
|
||||
class IndexGoods extends ApiRest
|
||||
{
|
||||
|
||||
@@ -34,7 +35,8 @@ class IndexGoods extends ApiRest
|
||||
|
||||
protected $car_model;
|
||||
|
||||
public function __construct(App $app) {
|
||||
public function __construct(App $app)
|
||||
{
|
||||
|
||||
parent::__construct($app);
|
||||
|
||||
@@ -47,44 +49,35 @@ class IndexGoods extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 11:57
|
||||
* @功能说明:首页选择店铺列表
|
||||
*/
|
||||
public function indexStoreList(){
|
||||
|
||||
public function indexStoreList()
|
||||
{
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
|
||||
$dis[] = ['status','=',2];
|
||||
|
||||
$dis[] = ['business_status','=',1];
|
||||
|
||||
if(!empty($input['store_name'])){
|
||||
|
||||
$dis[] = ['title','like','%'.$input['store_name'].'%'];
|
||||
$page = $input['page'] ?? 10;
|
||||
$dis[] = ['uniacid', '=', $this->_uniacid];
|
||||
$dis[] = ['status', '=', 2];
|
||||
$dis[] = ['business_status', '=', 1];
|
||||
if (!empty($input['store_name'])) {
|
||||
$dis[] = ['title', 'like', '%' . $input['store_name'] . '%'];
|
||||
}
|
||||
|
||||
$lat = !empty($input['lat'])?$input['lat']:0;
|
||||
|
||||
$lng = !empty($input['lng'])?$input['lng']:0;
|
||||
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*('.$lat.'-lat)/360),2)+COS(3.1415926535898*'.$lat.'/180)* COS('.$lat.' * 3.1415926535898/180)*POW(SIN(3.1415926535898*('.$lng.'-lng)/360),2))))*1000 as distance';
|
||||
|
||||
$alhs = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*('.$lat.'-lat)/360),2)+COS(3.1415926535898*'.$lat.'/180)* COS('.$lat.' * 3.1415926535898/180)*POW(SIN(3.1415926535898*('.$lng.'-lng)/360),2))))*1000<20000';
|
||||
|
||||
$lat = !empty($input['lat']) ? $input['lat'] : 0;
|
||||
$lng = !empty($input['lng']) ? $input['lng'] : 0;
|
||||
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*(' . $lat . '-lat)/360),2)+COS(3.1415926535898*' . $lat . '/180)* COS(' . $lat . ' * 3.1415926535898/180)*POW(SIN(3.1415926535898*(' . $lng . '-lng)/360),2))))*1000 as distance';
|
||||
$alhs = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*(' . $lat . '-lat)/360),2)+COS(3.1415926535898*' . $lat . '/180)* COS(' . $lat . ' * 3.1415926535898/180)*POW(SIN(3.1415926535898*(' . $lng . '-lng)/360),2))))*1000<20000';
|
||||
$store_model = new Farmer();
|
||||
|
||||
$data = $store_model->dataDistanceList($dis,$alh,$alhs,10);
|
||||
$data = $store_model->dataDistanceList($dis, $alh, $alhs, $page);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
foreach ($data['data'] as &$v) {
|
||||
|
||||
$v['distance'] = getDistances($v['lng'],$v['lat'],$lng,$lat);
|
||||
$v['distance'] = getDistances($v['lng'], $v['lat'], $lng, $lat);
|
||||
|
||||
$v['distance'] = $store_model->getDistanceAttr($v['distance']);
|
||||
|
||||
@@ -93,23 +86,22 @@ class IndexGoods extends ApiRest
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 13:24
|
||||
* @功能说明:选择门店
|
||||
*/
|
||||
public function selectStore(){
|
||||
public function selectStore()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$res = $user_model->dataUpdate(['id'=>$this->getUserId()],['last_store_id'=>$input['store_id']]);
|
||||
$res = $user_model->dataUpdate(['id' => $this->getUserId()], ['last_store_id' => $input['store_id']]);
|
||||
|
||||
return $this->success($res);
|
||||
|
||||
@@ -121,19 +113,20 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2021-03-18 16:46
|
||||
* @功能说明:分类列表
|
||||
*/
|
||||
public function goodsIndex(){
|
||||
public function goodsIndex()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$store_id = !empty($input['store_id'])?$input['store_id']:0;
|
||||
$store_id = !empty($input['store_id']) ? $input['store_id'] : 0;
|
||||
|
||||
$data['cate_id'] = $this->cate_model->shopCateList($this->_uniacid,$store_id);
|
||||
$data['cate_id'] = $this->cate_model->shopCateList($this->_uniacid, $store_id);
|
||||
|
||||
if(!empty($store_id)){
|
||||
if (!empty($store_id)) {
|
||||
|
||||
$store_model = new Farmer();
|
||||
|
||||
$data['store_info'] = $store_model->dataInfo(['id'=>$store_id]);
|
||||
$data['store_info'] = $store_model->dataInfo(['id' => $store_id]);
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
@@ -146,7 +139,8 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2022-03-01 13:47
|
||||
* @功能说明:
|
||||
*/
|
||||
public function haveSelectStoreId(){
|
||||
public function haveSelectStoreId()
|
||||
{
|
||||
|
||||
return $this->success($this->getStoreInfo()['id']);
|
||||
|
||||
@@ -158,48 +152,49 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2022-02-22 15:27
|
||||
* @功能说明:商品列表
|
||||
*/
|
||||
public function goodsList(){
|
||||
public function goodsList()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['a.uniacid','=',$this->_uniacid];
|
||||
$dis[] = ['a.uniacid', '=', $this->_uniacid];
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
$dis[] = ['a.status', '=', 1];
|
||||
|
||||
// $dis[] = ['a.index_show','=',1];
|
||||
// $dis[] = ['a.index_show','=',1];
|
||||
|
||||
$dis[] = ['d.status','=',2];
|
||||
$dis[] = ['d.status', '=', 2];
|
||||
|
||||
$dis[] = ['d.business_status','=',1];
|
||||
$dis[] = ['d.business_status', '=', 1];
|
||||
|
||||
if(!empty($input['store_id'])){
|
||||
if (!empty($input['store_id'])) {
|
||||
|
||||
$dis[] = ['b.store_id','=',$input['store_id']];
|
||||
$dis[] = ['b.store_id', '=', $input['store_id']];
|
||||
}
|
||||
|
||||
if(!empty($input['cate_id'])){
|
||||
if (!empty($input['cate_id'])) {
|
||||
|
||||
$dis[] = ['c.cate_id','=',$input['cate_id']];
|
||||
$dis[] = ['c.cate_id', '=', $input['cate_id']];
|
||||
|
||||
}
|
||||
|
||||
if(!empty($input['goods_name'])){
|
||||
if (!empty($input['goods_name'])) {
|
||||
|
||||
$dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];
|
||||
$dis[] = ['a.goods_name', 'like', '%' . $input['goods_name'] . '%'];
|
||||
|
||||
}
|
||||
//商品信息
|
||||
$data = $this->model->indexGoodsList($dis,10);
|
||||
$data = $this->model->indexGoodsList($dis, 10);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
if (!empty($data['data'])) {
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
foreach ($data['data'] as &$v) {
|
||||
|
||||
$where = [
|
||||
|
||||
'type' => 5,
|
||||
'type' => 5,
|
||||
|
||||
'user_id' => $this->getUserId()
|
||||
'user_id' => $this->getUserId()
|
||||
];
|
||||
|
||||
$v['car_count'] = $this->car_model->where($where)->count();
|
||||
@@ -213,13 +208,13 @@ class IndexGoods extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 15:46
|
||||
* @功能说明:商品详情
|
||||
*/
|
||||
public function goodsInfo(){
|
||||
public function goodsInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
@@ -230,9 +225,9 @@ class IndexGoods extends ApiRest
|
||||
|
||||
$data = $this->model->dataInfo($dis);
|
||||
|
||||
$farm_model = new Farmer();
|
||||
$farm_model = new Farmer();
|
||||
|
||||
$where[] = ['id','in',$data['store']];
|
||||
$where[] = ['id', 'in', $data['store']];
|
||||
|
||||
$data['store_info'] = $farm_model->dataInfo($where);
|
||||
|
||||
@@ -244,30 +239,30 @@ class IndexGoods extends ApiRest
|
||||
|
||||
'goods_id' => $input['id'],
|
||||
|
||||
'status' => 1
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$data['spe_text'] = $spe_model->goodsSpe($where);
|
||||
$data['spe_text'] = $spe_model->goodsSpe($where);
|
||||
|
||||
$data['spe_price'] = $spe_price_model->goodsSpePrice($where);
|
||||
|
||||
$kill_model = new SeckillList();
|
||||
$kill_model = new SeckillList();
|
||||
|
||||
$integral_model = new IntegralList();
|
||||
//秒杀活动
|
||||
$data['kill_list'] = $kill_model->atvIng($input['id'],0,2);
|
||||
$data['kill_list'] = $kill_model->atvIng($input['id'], 0, 2);
|
||||
|
||||
if(!empty($data['spe_price'])){
|
||||
if (!empty($data['spe_price'])) {
|
||||
|
||||
foreach ($data['spe_price'] as &$v){
|
||||
foreach ($data['spe_price'] as &$v) {
|
||||
//查询是否有秒杀活动
|
||||
$v['kill_atv'] = $kill_model->atvIng($input['id'],$v['id']);
|
||||
$v['kill_atv'] = $kill_model->atvIng($input['id'], $v['id']);
|
||||
|
||||
if(empty($v['kill_atv'])){
|
||||
if (empty($v['kill_atv'])) {
|
||||
//积分活动
|
||||
$v['integral_atv'] = $integral_model->atvIng($input['id'],$v['id']);
|
||||
$v['integral_atv'] = $integral_model->atvIng($input['id'], $v['id']);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$v['integral_atv'] = [];
|
||||
}
|
||||
@@ -281,42 +276,40 @@ class IndexGoods extends ApiRest
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-24 14:07
|
||||
* @功能说明:购物车信息
|
||||
*/
|
||||
public function carInfo(){
|
||||
public function carInfo()
|
||||
{
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$store_id = !empty($input['store_id'])?$input['store_id']:0;
|
||||
$store_id = !empty($input['store_id']) ? $input['store_id'] : 0;
|
||||
//购物车信息
|
||||
$car_info = $this->car_model->carPriceAndCount($this->getUserId(),$store_id,1);
|
||||
$car_info = $this->car_model->carPriceAndCount($this->getUserId(), $store_id, 1);
|
||||
|
||||
return $this->success($car_info);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-24 14:46
|
||||
* @功能说明:添加到购物车
|
||||
*/
|
||||
public function addCar(){
|
||||
public function addCar()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
$is_show_del = !empty($input['is_show_del'])?$input['is_show_del']:1;
|
||||
$is_show_del = !empty($input['is_show_del']) ? $input['is_show_del'] : 1;
|
||||
|
||||
if($is_show_del==1){
|
||||
if ($is_show_del == 1) {
|
||||
|
||||
$this->car_model->where(['user_id'=>$this->getUserId(),'is_show'=>2])->delete();
|
||||
$this->car_model->where(['user_id' => $this->getUserId(), 'is_show' => 2])->delete();
|
||||
}
|
||||
|
||||
$insert = [
|
||||
@@ -325,31 +318,31 @@ class IndexGoods extends ApiRest
|
||||
|
||||
'user_id' => $this->getUserId(),
|
||||
|
||||
'farmer_id'=> $input['store_id'],
|
||||
'farmer_id' => $input['store_id'],
|
||||
|
||||
'goods_id'=> $input['goods_id'],
|
||||
'goods_id' => $input['goods_id'],
|
||||
|
||||
'spe_id' => $input['spe_id'],
|
||||
'spe_id' => $input['spe_id'],
|
||||
|
||||
'type' => 5,
|
||||
'type' => 5,
|
||||
|
||||
'is_show' => !empty($input['is_show'])?$input['is_show']:1,
|
||||
'is_show' => !empty($input['is_show']) ? $input['is_show'] : 1,
|
||||
|
||||
];
|
||||
|
||||
$input['goods_num'] = !empty($input['goods_num'])?$input['goods_num']:1;
|
||||
$input['goods_num'] = !empty($input['goods_num']) ? $input['goods_num'] : 1;
|
||||
|
||||
$info = $this->car_model->dataInfo($insert);
|
||||
//增加数量
|
||||
if(!empty($info)){
|
||||
if (!empty($info)) {
|
||||
|
||||
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']+$input['goods_num']]);
|
||||
$res = $this->car_model->dataUpdate(['id' => $info['id']], ['goods_num' => $info['goods_num'] + $input['goods_num']]);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
//添加到购物车
|
||||
$insert['goods_num'] = $input['goods_num'];
|
||||
|
||||
$insert['status'] = 1;
|
||||
$insert['status'] = 1;
|
||||
|
||||
$res = $this->car_model->dataAdd($insert);
|
||||
|
||||
@@ -365,21 +358,22 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2021-03-24 14:54
|
||||
* @功能说明:删除购物车
|
||||
*/
|
||||
public function delCar(){
|
||||
public function delCar()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
$info = $this->car_model->dataInfo(['id'=>$input['id']]);
|
||||
$info = $this->car_model->dataInfo(['id' => $input['id']]);
|
||||
|
||||
$input['goods_num'] = !empty($input['goods_num'])?$input['goods_num']:1;
|
||||
$input['goods_num'] = !empty($input['goods_num']) ? $input['goods_num'] : 1;
|
||||
//加少数量
|
||||
if($info['goods_num']>$input['goods_num']){
|
||||
if ($info['goods_num'] > $input['goods_num']) {
|
||||
|
||||
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']-$input['goods_num']]);
|
||||
$res = $this->car_model->dataUpdate(['id' => $info['id']], ['goods_num' => $info['goods_num'] - $input['goods_num']]);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$res = $this->car_model->where(['id'=>$info['id']])->delete();
|
||||
$res = $this->car_model->where(['id' => $info['id']])->delete();
|
||||
}
|
||||
|
||||
return $this->success($res);
|
||||
@@ -392,17 +386,18 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2021-03-25 10:39
|
||||
* @功能说明:
|
||||
*/
|
||||
public function carUpdate(){
|
||||
public function carUpdate()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
if(!empty($input['id'])){
|
||||
if (!empty($input['id'])) {
|
||||
|
||||
$res = $this->car_model->where('id','in',$input['id'])->update(['status'=>$input['status']]);
|
||||
$res = $this->car_model->where('id', 'in', $input['id'])->update(['status' => $input['status']]);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$res = $this->car_model->where('user_id','=',$this->getUserId())->update(['status'=>$input['status']]);
|
||||
$res = $this->car_model->where('user_id', '=', $this->getUserId())->update(['status' => $input['status']]);
|
||||
}
|
||||
|
||||
return $this->success($res);
|
||||
@@ -415,7 +410,8 @@ class IndexGoods extends ApiRest
|
||||
* @DataTime: 2021-03-24 14:59
|
||||
* @功能说明:批量删除购物车
|
||||
*/
|
||||
public function delSomeCar(){
|
||||
public function delSomeCar()
|
||||
{
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
@@ -425,9 +421,9 @@ class IndexGoods extends ApiRest
|
||||
|
||||
'user_id' => $this->getUserId(),
|
||||
|
||||
'farmer_id'=> $this->getStoreInfo()['id'],
|
||||
'farmer_id' => $this->getStoreInfo()['id'],
|
||||
|
||||
'type' => 5,
|
||||
'type' => 5,
|
||||
|
||||
];
|
||||
|
||||
|
||||
@@ -497,6 +497,8 @@ Route::group('app', function () {
|
||||
Route::get('Index/aboutUsList', 'Index/aboutUsList');
|
||||
//获取配置信息
|
||||
Route::get('Index/configInfo', 'Index/configInfo');
|
||||
// 农场
|
||||
Route::get('Index/indexStoreList', 'Index/indexStoreList');
|
||||
//文章详情(id)
|
||||
Route::get('Index/articleInfo', 'Index/articleInfo');
|
||||
//模版列表
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\massage\model;
|
||||
|
||||
use app\BaseModel;
|
||||
@@ -16,7 +17,8 @@ class Config extends BaseModel
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
public function dataAdd($data)
|
||||
{
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
@@ -25,13 +27,13 @@ class Config extends BaseModel
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
public function dataUpdate($dis, $data)
|
||||
{
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
@@ -45,12 +47,10 @@ class Config extends BaseModel
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
public function dataList($dis, $page)
|
||||
{
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -59,26 +59,16 @@ class Config extends BaseModel
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
public function dataInfo($dis)
|
||||
{
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
if (empty($data)) {
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
}
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
return !empty($data) ? $data->toArray() : [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
196
doc/backend-technical-deep-dive.md
Normal file
196
doc/backend-technical-deep-dive.md
Normal file
@@ -0,0 +1,196 @@
|
||||
# 后端架构深度解析与开发指南
|
||||
|
||||
## 1. 引言
|
||||
|
||||
本文档旨在为开发人员提供一份关于本项目(智慧农场系统)后端架构的深度技术解析。不同于基础的架构介绍,本文档聚焦于**代码实现细节**、**数据库设计范式**以及**核心业务流程**的底层逻辑。它将帮助你在接手项目后,快速理解现有代码模式(Patterns),并安全、高效地扩展新功能。
|
||||
|
||||
---
|
||||
|
||||
## 2. 核心架构与技术实现
|
||||
|
||||
本项目基于 **ThinkPHP 6** 框架开发,采用了典型的 **MVC** 架构,并结合了多应用(Multi-app)模式。
|
||||
|
||||
### 2.1 C层(Controller)技术实现
|
||||
|
||||
控制器层主要负责请求接收、参数校验和业务调度。项目在控制器层有以下显著的实现模式:
|
||||
|
||||
#### 2.1.1 基类封装 (`app/ApiRest.php`)
|
||||
所有 API 控制器均继承自 `app\ApiRest`,该基类提供了以下核心能力:
|
||||
|
||||
- **统一响应格式**:通过 `success($data)` 和 `error($msg)` 方法,强制统一 API 返回结构:
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"data": { ... },
|
||||
"sign": "..." // 签名(可选)
|
||||
}
|
||||
```
|
||||
- **多租户隔离**:在构造函数中自动解析 `uniacid`(商户/租户ID),并赋值给 `$this->_uniacid`。这是系统支持多商户SaaS模式的核心。
|
||||
- **鉴权机制**:
|
||||
- 检查 HTTP Header 中的 `autograph`(小程序用户标识)。
|
||||
- 维护一个 `$noNeedLogin` 白名单。
|
||||
- **注意**:`shareChangeData` 方法中硬编码了大量白名单路由,这种实现方式维护成本较高,建议后续改为中间件或注解配置。
|
||||
|
||||
#### 2.1.2 胖模型,瘦控制器
|
||||
控制器(如 `app/farm/controller/IndexLand.php`)通常比较轻量,不包含复杂的计算逻辑。
|
||||
- **示例**:在“土地下单”流程中,价格计算、优惠券抵扣等逻辑全部下沉到了 Model 层 (`LandOrder::payOrderInfo`)。
|
||||
- **优点**:业务逻辑可复用,控制器代码整洁。
|
||||
|
||||
### 2.2 M层(Model)技术实现
|
||||
|
||||
模型层不仅负责数据库交互,还承担了大部分业务逻辑。
|
||||
|
||||
#### 2.2.1 基类扩展 (`app/BaseModel.php`)
|
||||
- 实现了基础的 CRUD 方法(`getRow`, `listRow`, `createRow` 等)。
|
||||
- **软删除机制**:手动实现了基于 `deleted` 字段和 `delete_time` 的软删除,未使用 TP 自带的 `SoftDelete` Trait。
|
||||
- **代码现状**:核心业务 Model(如 `LandOrder`)往往重写了 `dataAdd`/`dataUpdate` 方法,直接调用 TP 的 `insert`/`update`,并未完全依赖 `BaseModel` 的封装。这导致项目中存在两种 CRUD 风格。
|
||||
|
||||
#### 2.2.2 高级特性应用
|
||||
- **获取器 (Getters)**:大量使用 TP 的获取器处理字段格式化。例如 `LandList::getImgsAttr` 将数据库存储的逗号分隔字符串自动转换为数组。
|
||||
- **动态追加字段**:使用 `$append` 属性在 JSON 序列化时追加计算字段(如 `min_price`)。
|
||||
- **观察者模式**:在 `LandList::updateSome` 中,手动实现了观察者模式 (`app\farm\server\Land`) 来同步更新关联表数据。这是项目中少见的设计模式应用,值得保留和参考。
|
||||
|
||||
---
|
||||
|
||||
## 3. 数据库深度解析
|
||||
|
||||
### 3.1 数据库概览
|
||||
- **引擎**:大部分表使用 `MyISAM`。
|
||||
- **风险**:MyISAM 不支持事务,且在并发写入时是表级锁。对于涉及资金交易的表(如 `balance_water`, `land_order`),强烈建议迁移到 `InnoDB`。
|
||||
- **字符集**:`utf8` / `utf8mb4`。
|
||||
- **多租户设计**:几乎所有表都包含 `uniacid` 字段,用于物理隔离不同商户的数据。
|
||||
|
||||
### 3.2 核心业务实体关系 (ER图)
|
||||
|
||||
以下是“土地认养”核心业务的实体关系推导:
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
User ||--o{ LandOrder : "下单"
|
||||
User ||--o{ Address : "拥有"
|
||||
Farmer ||--o{ LandList : "管理"
|
||||
LandList ||--|{ LandSpe : "包含规格"
|
||||
LandList ||--o{ LandMassif : "包含地块"
|
||||
LandOrder }|--|| LandList : "关联土地"
|
||||
LandOrder }|--|| LandSpe : "关联规格"
|
||||
LandOrder }|--|| LandMassif : "关联地块"
|
||||
LandOrder ||--|{ LandOrderSeed : "包含种子"
|
||||
|
||||
User {
|
||||
int id PK
|
||||
int uniacid
|
||||
string openid
|
||||
string nickName
|
||||
}
|
||||
|
||||
LandList {
|
||||
int id PK
|
||||
int farmer_id FK "农场主"
|
||||
string title "土地名称"
|
||||
int status
|
||||
}
|
||||
|
||||
LandOrder {
|
||||
int id PK
|
||||
string order_code "订单号"
|
||||
decimal pay_price "支付金额"
|
||||
int pay_type "1:未支付 2:已支付"
|
||||
int status
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 关键表结构解析
|
||||
|
||||
#### 1. `ims_lbfarm_land_list` (土地表)
|
||||
- 核心商品表,存储土地的基本信息。
|
||||
- 关联表:`ims_lbfarm_land_spe` (规格), `ims_lbfarm_land_massif` (地块/位置)。
|
||||
|
||||
#### 2. `ims_lbfarm_land_order` (土地订单表)
|
||||
- **核心字段**:
|
||||
- `order_code`: 业务订单号。
|
||||
- `transaction_id`: 微信支付流水号。
|
||||
- `pay_type`: 支付状态 (1=未支付, 2=微信支付, 3=余额支付)。
|
||||
- `seed_data`: 种子信息的 JSON 快照(反范式设计,避免关联查询)。
|
||||
|
||||
---
|
||||
|
||||
## 4. 核心业务流程剖析
|
||||
|
||||
### 4.1 土地认养下单与支付流程
|
||||
|
||||
这是一个跨越 Controller、Model 和 Service 的复杂流程:
|
||||
|
||||
1. **预下单 (计价)**
|
||||
- **入口**:`IndexLand::landPayOrderInfo`
|
||||
- **逻辑**:调用 `LandOrder::payOrderInfo`。
|
||||
- **计算公式**:`总价 = 土地规格单价 + (地块单价 * 认养周期) + ∑(种子单价 * 数量) - 优惠券金额`。
|
||||
|
||||
2. **创建订单**
|
||||
- **入口**:`IndexLand::landPayOrder`
|
||||
- **逻辑**:再次调用 `payOrderInfo` 校验价格,然后写入 `land_order` 表,同时写入 `land_order_seed` 表。
|
||||
|
||||
3. **支付回调 (核心)**
|
||||
- **逻辑位置**:`LandOrder::orderResult`
|
||||
- **事务处理**:
|
||||
1. 开启事务 (`Db::startTrans()`)。
|
||||
2. 更新订单状态 (`pay_type=2`, `pay_time`)。
|
||||
3. **余额扣除**:如果使用了余额抵扣,调用 `BalanceWater::addWater`。
|
||||
4. **资金流水**:记录 `FinanceWater`。
|
||||
5. **分销结算**:调用 `DistributionCash::addUserCash` 计算分销佣金。
|
||||
6. 提交事务 (`Db::commit()`)。
|
||||
- **后续动作**:发送微信订阅消息 (`paySendService`),这是异步或非事务性的操作,放在 commit 之后执行是正确的。
|
||||
|
||||
---
|
||||
|
||||
## 5. 开发实战指南
|
||||
|
||||
### 5.1 如何新增一个 API 接口?
|
||||
|
||||
假设你需要新增一个“获取最近的农场列表”接口:
|
||||
|
||||
1. **创建控制器**:
|
||||
在 `app/farm/controller` 下创建 `IndexFarm.php`,继承 `ApiRest`。
|
||||
```php
|
||||
class IndexFarm extends ApiRest {
|
||||
public function nearby() {
|
||||
$lat = $this->_param['lat'];
|
||||
$lng = $this->_param['lng'];
|
||||
// 调用 Model 获取数据
|
||||
$data = (new Farmer())->getNearby($lat, $lng);
|
||||
return $this->success($data);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **实现 Model 逻辑**:
|
||||
在 `app/farm/model/Farmer.php` 中实现 `getNearby` 方法。建议参考 `LandList::indexDataList` 中的距离计算 SQL。
|
||||
|
||||
3. **配置路由**:
|
||||
在 `app/farm/route/route.php` 中注册路由(如果项目未开启自动路由)。目前看项目启用了自动路由,直接访问 `farm/index_farm/nearby` 即可。
|
||||
|
||||
4. **配置鉴权**:
|
||||
如果该接口不需要登录,需要在 `ApiRest::shareChangeData` 或控制器的构造函数中将其加入 `$noNeedLogin` 数组。
|
||||
|
||||
### 5.2 常见坑与规避
|
||||
|
||||
1. **数据库事务**:
|
||||
由于大量表使用 `MyISAM`,在涉及多表更新时(如订单状态+库存扣减),事务可能不会生效。
|
||||
- **建议**:在开发新功能涉及核心交易表时,务必检查表引擎,必要时手动 `ALTER TABLE ... ENGINE=InnoDB`。
|
||||
|
||||
2. **参数获取**:
|
||||
尽量使用 `$this->_param` 获取参数,它合并了 GET 和 POST 数据。避免直接使用 `$_GET` 或 `$_POST`。
|
||||
|
||||
3. **浮点数计算**:
|
||||
项目中存在直接使用浮点数计算金额的情况(如 `round($price, 2)`)。在涉及金额比对时,建议使用 `bccomp` 等高精度函数,避免精度丢失导致的 0.01 元误差。
|
||||
|
||||
4. **SQL 注入风险**:
|
||||
虽然 TP 的 ORM 有防注入机制,但在拼接原生 SQL(如距离计算)时,务必使用参数绑定,严禁直接拼接变量。
|
||||
|
||||
---
|
||||
|
||||
## 6. 附录:推荐的重构方向
|
||||
|
||||
1. **引入 .env 配置**:将 `config/database.php` 中的硬编码配置移至环境变量。
|
||||
2. **统一 Model 规范**:废弃 `dataAdd` 等自定义方法,统一使用 TP 标准的 `save/create`,或完善 `BaseModel` 并强制继承。
|
||||
3. **中间件鉴权**:将 `ApiRest` 中的硬编码鉴权逻辑重构为 TP 中间件。
|
||||
4. **数据库迁移**:编写脚本将所有 `MyISAM` 表迁移至 `InnoDB`。
|
||||
2138
doc/stsm_farm.sql
Normal file
2138
doc/stsm_farm.sql
Normal file
File diff suppressed because it is too large
Load Diff
43
vendor/topthink/framework/src/helper.php
vendored
43
vendor/topthink/framework/src/helper.php
vendored
@@ -202,6 +202,34 @@ if (!function_exists('dump')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('dd')) {
|
||||
/**
|
||||
* 浏览器友好的变量输出
|
||||
* @param mixed $vars 要输出的变量
|
||||
* @return void
|
||||
*/
|
||||
function dd(...$vars)
|
||||
{
|
||||
ob_start();
|
||||
var_dump(...$vars);
|
||||
|
||||
$output = ob_get_clean();
|
||||
$output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
|
||||
|
||||
if (PHP_SAPI == 'cli') {
|
||||
$output = PHP_EOL . $output . PHP_EOL;
|
||||
} else {
|
||||
if (!extension_loaded('xdebug')) {
|
||||
$output = htmlspecialchars($output, ENT_SUBSTITUTE);
|
||||
}
|
||||
$output = '<pre>' . $output . '</pre>';
|
||||
}
|
||||
|
||||
echo $output;
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('env')) {
|
||||
/**
|
||||
* 获取环境变量值
|
||||
@@ -661,3 +689,18 @@ if (!function_exists('root_path')) {
|
||||
return app()->getRootPath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_dev')) {
|
||||
function is_dev()
|
||||
{
|
||||
$env = env('APP_ENV', '');
|
||||
$env = strtolower($env);
|
||||
if (in_array($env, ['dev', 'development', 'local', 'test'], true)) {
|
||||
return true;
|
||||
}
|
||||
if (app()->environment('dev') || app()->environment('local') || app()->environment('test')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user