优化代码

This commit is contained in:
2026-01-04 15:34:23 +08:00
parent dffbb12d29
commit 437c5796ea
2 changed files with 77 additions and 69 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace app\farm\model; namespace app\farm\model;
use app\BaseModel; use app\BaseModel;
@@ -21,18 +22,19 @@ class Farmer extends BaseModel
* @DataTime: 2022-03-02 17:12 * @DataTime: 2022-03-02 17:12
* @功能说明: * @功能说明:
*/ */
public function getTimeStatusAttr($value,$data){ public function getTimeStatusAttr($value, $data)
{
if(!empty($data['start_time'])&&!empty($data['end_time'])){ if (!empty($data['start_time']) && !empty($data['end_time'])) {
$start_time = strtotime($data['start_time']); $start_time = strtotime($data['start_time']);
$end_time = strtotime($data['end_time']); $end_time = strtotime($data['end_time']);
if($start_time<time()&&$end_time>time()){ if ($start_time < time() && $end_time > time()) {
return 1; return 1;
}else{ } else {
return 0; return 0;
} }
@@ -47,11 +49,12 @@ class Farmer extends BaseModel
* @DataTime: 2021-12-30 11:22 * @DataTime: 2021-12-30 11:22
* @功能说明: * @功能说明:
*/ */
public function getImgsAttr($value,$data){ public function getImgsAttr($value, $data)
{
if(!empty($value)){ if (!empty($value)) {
return explode(',',$value); return explode(',', $value);
} }
} }
@@ -61,20 +64,23 @@ class Farmer extends BaseModel
* @DataTime: 2021-12-30 11:22 * @DataTime: 2021-12-30 11:22
* @功能说明: * @功能说明:
*/ */
public function getIdcardImgsAttr($value,$data){ public function getIdcardImgsAttr($value, $data)
{
if(!empty($value)){ if (!empty($value)) {
return explode(',',$value); return explode(',', $value);
} }
} }
/** /**
* @author chenniang * @author chenniang
* @DataTime: 2020-09-29 11:04 * @DataTime: 2020-09-29 11:04
* @功能说明:添加 * @功能说明:添加
*/ */
public function dataAdd($data){ public function dataAdd($data)
{
$data['create_time'] = time(); $data['create_time'] = time();
@@ -85,13 +91,13 @@ class Farmer extends BaseModel
} }
/** /**
* @author chenniang * @author chenniang
* @DataTime: 2020-09-29 11:05 * @DataTime: 2020-09-29 11:05
* @功能说明:编辑 * @功能说明:编辑
*/ */
public function dataUpdate($dis,$data){ public function dataUpdate($dis, $data)
{
$res = $this->where($dis)->update($data); $res = $this->where($dis)->update($data);
@@ -105,7 +111,8 @@ class Farmer extends BaseModel
* @DataTime: 2020-09-29 11:06 * @DataTime: 2020-09-29 11:06
* @功能说明:列表 * @功能说明:列表
*/ */
public function dataList($dis,$page=10){ public function dataList($dis, $page = 10)
{
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray(); $data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
@@ -119,9 +126,10 @@ class Farmer extends BaseModel
* @DataTime: 2020-09-29 11:06 * @DataTime: 2020-09-29 11:06
* @功能说明:列表 * @功能说明:列表
*/ */
public function dataDistanceList($dis,$alh,$alhs=[],$page=10){ public function dataDistanceList($dis, $alh, $alhs = [], $page = 10)
{
$data = $this->where($dis)->where($alhs)->field(['*',$alh])->order('distance asc,id desc')->paginate($page)->toArray(); $data = $this->where($dis)->where($alhs)->field(['*', $alh])->order('distance asc,id desc')->paginate($page)->toArray();
return $data; return $data;
@@ -133,19 +141,20 @@ class Farmer extends BaseModel
* @DataTime: 2021-12-30 11:26 * @DataTime: 2021-12-30 11:26
* @功能说明:后台列表 * @功能说明:后台列表
*/ */
public function adminDataList($dis,$page=10,$where=[]){ public function adminDataList($dis, $page = 10, $where = [])
{
$data = $this->alias('a') $data = $this->alias('a')
->join('lbfarm_user_list b','a.user_id = b.id','left') ->join('lbfarm_user_list b', 'a.user_id = b.id', 'left')
->where($dis) ->where($dis)
->where(function ($query) use ($where){ ->where(function ($query) use ($where) {
$query->whereOr($where); $query->whereOr($where);
}) })
->field('a.*,b.nickName,b.avatarUrl') ->field('a.*,b.nickName,b.avatarUrl')
->group('a.id') ->group('a.id')
->order('a.id desc') ->order('a.id desc')
->paginate($page) ->paginate($page)
->toArray(); ->toArray();
return $data; return $data;
@@ -157,11 +166,12 @@ class Farmer extends BaseModel
* @DataTime: 2020-09-29 11:43 * @DataTime: 2020-09-29 11:43
* @功能说明: * @功能说明:
*/ */
public function dataInfo($dis,$file='*'){ public function dataInfo($dis, $file = '*')
{
$data = $this->where($dis)->field($file)->find(); $data = $this->where($dis)->field($file)->find();
return !empty($data)?$data->toArray():[]; return !empty($data) ? $data->toArray() : [];
} }
@@ -171,13 +181,14 @@ class Farmer extends BaseModel
* @DataTime: 2022-02-22 11:30 * @DataTime: 2022-02-22 11:30
* @功能说明:检查用户是否是地主 * @功能说明:检查用户是否是地主
*/ */
public function landlordCheck($user_id){ public function landlordCheck($user_id)
{
$cap_dis[] = ['user_id','=',$user_id]; $cap_dis[] = ['user_id', '=', $user_id];
$cap_dis[] = ['type','=',1]; $cap_dis[] = ['type', '=', 1];
$cap_dis[] = ['status','in',[2,3]]; $cap_dis[] = ['status', 'in', [2, 3]];
$farmer_model = new \app\farm\model\Farmer(); $farmer_model = new \app\farm\model\Farmer();
//查看是否是团长 //查看是否是团长
@@ -185,17 +196,17 @@ class Farmer extends BaseModel
$is_landlord = 1; $is_landlord = 1;
if(empty($cap_info)){ if (empty($cap_info)) {
$order_model = new LandOrder(); $order_model = new LandOrder();
$where[] = ['pay_type','>',1]; $where[] = ['pay_type', '>', 1];
$where[] = ['user_id','=',$user_id]; $where[] = ['user_id', '=', $user_id];
//是否有土地订单 //是否有土地订单
$order = $order_model->dataInfo($where); $order = $order_model->dataInfo($where);
if(empty($order)){ if (empty($order)) {
$is_landlord = 0; $is_landlord = 0;
@@ -205,7 +216,7 @@ class Farmer extends BaseModel
$user_model = new User(); $user_model = new User();
$user_model->dataUpdate(['id'=>$user_id],['is_landlord'=>$is_landlord]); $user_model->dataUpdate(['id' => $user_id], ['is_landlord' => $is_landlord]);
return $is_landlord; return $is_landlord;
} }
@@ -216,11 +227,12 @@ class Farmer extends BaseModel
* @DataTime: 2022-02-22 11:53 * @DataTime: 2022-02-22 11:53
* @功能说明:初始化地主表 * @功能说明:初始化地主表
*/ */
public function initLandLord($data,$uniacid){ public function initLandLord($data, $uniacid)
{
$dis = [ $dis = [
'type' => 2, 'type' => 2,
'user_id' => $data['user_id'], 'user_id' => $data['user_id'],
@@ -229,7 +241,7 @@ class Farmer extends BaseModel
$find = $this->dataInfo($dis); $find = $this->dataInfo($dis);
if(empty($find)){ if (empty($find)) {
$dis['status'] = 2; $dis['status'] = 2;
@@ -251,7 +263,7 @@ class Farmer extends BaseModel
$user_model = new User(); $user_model = new User();
$user_model->dataUpdate(['id'=>$data['user_id']],['is_landlord'=>1]); $user_model->dataUpdate(['id' => $data['user_id']], ['is_landlord' => 1]);
} }
return true; return true;
@@ -262,22 +274,23 @@ class Farmer extends BaseModel
* @DataTime: 2020-10-21 15:21 * @DataTime: 2020-10-21 15:21
* @功能说明:保留两位小数 * @功能说明:保留两位小数
*/ */
public function getDistanceAttr($value){ public function getDistanceAttr($value)
{
if(!empty($value)){ if (!empty($value)) {
if($value>1000){ if ($value > 1000) {
$value = $value/1000; $value = $value / 1000;
$value = round($value,2); $value = round($value, 2);
$value = $value.'km'; $value = $value . 'km';
}else{ } else {
$value = round($value,2); $value = round($value, 2);
$value = $value.'m'; $value = $value . 'm';
} }
@@ -288,30 +301,29 @@ class Farmer extends BaseModel
} }
/** /**
* @author chenniang * @author chenniang
* @DataTime: 2022-02-28 14:08 * @DataTime: 2022-02-28 14:08
* @功能说明:添加商品时农场主下拉框 * @功能说明:添加商品时农场主下拉框
*/ */
public function goodsFarmerSelect($user_id){ public function goodsFarmerSelect($user_id)
{
$land_order_model = new LandOrder(); $land_order_model = new LandOrder();
$dis[] = ['user_id','=',$user_id]; $dis[] = ['user_id', '=', $user_id];
$dis[] = ['pay_type','>',1]; $dis[] = ['pay_type', '>', 1];
//购买土地对农场主id //购买土地对农场主id
$order_farmer = $land_order_model->where($dis)->column('farmer_id'); $order_farmer = $land_order_model->where($dis)->column('farmer_id');
$where[] = ['user_id','=',$user_id]; $where[] = ['user_id', '=', $user_id];
$where[] = ['status','in',[2,3]]; $where[] = ['status', 'in', [2, 3]];
//如果自己是农场主 //如果自己是农场主
$farmer = $this->where($where)->column('id'); $farmer = $this->where($where)->column('id');
$order_farmer = array_merge($order_farmer,$farmer); $order_farmer = array_merge($order_farmer, $farmer);
return $order_farmer; return $order_farmer;
} }
@@ -322,13 +334,14 @@ class Farmer extends BaseModel
* @DataTime: 2022-02-28 16:06 * @DataTime: 2022-02-28 16:06
* @功能说明: * @功能说明:
*/ */
public function farmerId($uniacid){ public function farmerId($uniacid)
{
$dis = [ $dis = [
'status' => 2, 'status' => 2,
'uniacid'=> $uniacid 'uniacid' => $uniacid
]; ];
$id = $this->where($dis)->column('id'); $id = $this->where($dis)->column('id');
@@ -338,7 +351,4 @@ class Farmer extends BaseModel
} }
}
}

View File

@@ -698,9 +698,7 @@ if (!function_exists('is_dev')) {
if (in_array($env, ['dev', 'development', 'local', 'test'], true)) { if (in_array($env, ['dev', 'development', 'local', 'test'], true)) {
return true; return true;
} }
if (app()->environment('dev') || app()->environment('local') || app()->environment('test')) {
return true;
}
return false; return false;
} }
} }