Compare commits
8 Commits
818b45fc01
...
68951aabaf
Author | SHA1 | Date |
---|---|---|
yaooo | 68951aabaf | |
yaooo | a427b35865 | |
weiz | ed00ed2786 | |
weiz | b0073c93e7 | |
weiz | 2cc4165de6 | |
weiz | 8ad44e8b05 | |
weiz | f5e4a5eafa | |
weiz | 5eff598ff7 |
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\action\Action;
|
||||
use app\common\model\action\ActionPic;
|
||||
use think\facade\Db;
|
||||
|
||||
class ActionController extends BaseApiController
|
||||
{
|
||||
protected array $actionFields = [
|
||||
1 => ['kind','breed','dosage','start_date','end_date','area','user','pic','remark'],//施肥操作字段
|
||||
2 => ['kind','breed','dosage','start_date','end_date','area','user','pic','remark'],//除草操作字段
|
||||
3 => ['type','start_date','end_date','area','user','pic','remark'],//灌溉操作字段
|
||||
4 => ['kind','breed','dosage','start_date','end_date','area','user','pic','remark'],//除虫操作字段
|
||||
5 => ['area','user','pic','remark'],//收获操作字段
|
||||
];
|
||||
protected array $actionMessage = [
|
||||
1 => '施肥操作',
|
||||
2 => '除草操作',
|
||||
3 => '灌溉操作',
|
||||
4 => '除虫操作',
|
||||
5 => '收获操作',
|
||||
];
|
||||
|
||||
//添加操作
|
||||
public function add() {
|
||||
$params = $this->request->post(['land_id','type','detail']);
|
||||
if(empty($params['land_id']) || empty($params['type']) || empty($params['detail'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
if(!in_array($params['type'],[1,2,3,4,5,6])){
|
||||
return $this->fail('操作类型错误');
|
||||
}
|
||||
$detail = json_decode($params['detail'],true);
|
||||
if(empty($detail)){
|
||||
return $this->fail('请填写操作格式错误');
|
||||
}
|
||||
foreach($this->actionFields[$params['type']] as $v) {
|
||||
if(empty($detail[$v])){
|
||||
return $this->fail($this->actionMessage[$params['type']].'缺少必要参数');
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$actionModel = new Action();
|
||||
$actionPicModel = new ActionPic();
|
||||
$actionModel->save([
|
||||
'land_id' => $params['land_id'],
|
||||
'type' => $params['type'],
|
||||
'detail' => $params['detail'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return $this->success('操作添加成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ namespace app\api\controller;
|
|||
|
||||
|
||||
use app\api\logic\IndexLogic;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use think\facade\Log;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
|
@ -28,7 +30,7 @@ class IndexController extends BaseApiController
|
|||
{
|
||||
|
||||
|
||||
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate'];
|
||||
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate','code'];
|
||||
|
||||
|
||||
/**
|
||||
|
@ -90,5 +92,37 @@ class IndexController extends BaseApiController
|
|||
return $this->data($result);
|
||||
}
|
||||
|
||||
// 获取短信验证码
|
||||
public function code(): Json
|
||||
{
|
||||
//验证请求方式
|
||||
if(!$this->request->isPost()){
|
||||
return $this->fail('请求方式错误');
|
||||
}
|
||||
//获取参数
|
||||
$params = $this->request->post(['phone','scene']);
|
||||
if(empty($params['phone']) || empty($params['scene'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA])){
|
||||
return $this->fail('短信场景错误');
|
||||
}
|
||||
//发送短信
|
||||
try {
|
||||
$result = event('Notice', [
|
||||
'scene_id' => $params['scene'],
|
||||
'params' => [
|
||||
'mobile' => $params['phone'],
|
||||
'code' => mt_rand(100000, 999999),
|
||||
]
|
||||
]);
|
||||
return $this->success($result[0]);
|
||||
}catch(\Exception $e){
|
||||
//记录日志
|
||||
Log::error($e->getMessage());
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\geo\City;
|
||||
use app\common\model\geo\County;
|
||||
use app\common\model\geo\Group;
|
||||
use app\common\model\geo\Province;
|
||||
use app\common\model\geo\Town;
|
||||
use app\common\model\geo\Village;
|
||||
use app\common\model\land\Land;
|
||||
use think\response\Json;
|
||||
|
||||
class LandController extends BaseApiController
|
||||
{
|
||||
//土地列表
|
||||
public function list(): Json
|
||||
{
|
||||
$params = $this->request->post(['page_no','page_size']);
|
||||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||||
$pageSize = empty($params['page_size']) ? 6 : $params['page_size'];
|
||||
$data = Land::where('user_id',$this->userId)->page($pageNo,$pageSize)->order('create_time desc')->select()->each(function($item){
|
||||
$item['pic'] = json_decode($item['pic']);
|
||||
return $item;
|
||||
})->toArray();
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//添加土地
|
||||
public function add(): Json
|
||||
{
|
||||
//获取参数并验证
|
||||
$fields = ['title','area','province_code','city_code','county_code','town_code','village_code','group_code','master_name','master_phone','pic'];
|
||||
$params = $this->request->post($fields);
|
||||
foreach($fields as $v){
|
||||
if(!isset($params[$v]) || $params[$v] == ''){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
}
|
||||
//验证土地是否存在
|
||||
$land = Land::where('user_id',$this->userId)->where('title',$params['title'])->findOrEmpty();
|
||||
if(!$land->isEmpty()){
|
||||
return $this->fail('土地名称已存在');
|
||||
}
|
||||
//获取省市县镇村组名称
|
||||
$province = Province::field('province_name')->where('province_code',$params['province_code'])->findOrEmpty();
|
||||
if($province->isEmpty()){
|
||||
return $this->fail('省份编码错误');
|
||||
}
|
||||
$city = City::field('city_name')->where('province_code',$params['province_code'])->where('city_code',$params['city_code'])->findOrEmpty();
|
||||
if($city->isEmpty()){
|
||||
return $this->fail('城市编码错误');
|
||||
}
|
||||
$county = County::field('county_name')->where('city_code',$params['city_code'])->where('county_code',$params['county_code'])->findOrEmpty();
|
||||
if($county->isEmpty()){
|
||||
return $this->fail('区县编码错误');
|
||||
}
|
||||
$town = Town::field('town_name')->where('county_code',$params['county_code'])->where('town_code',$params['town_code'])->findOrEmpty();
|
||||
if($town->isEmpty()){
|
||||
return $this->fail('镇街编码错误');
|
||||
}
|
||||
$village = Village::field('village_name')->where('town_code',$params['town_code'])->where('village_code',$params['village_code'])->findOrEmpty();
|
||||
if($village->isEmpty()){
|
||||
return $this->fail('乡村编码错误');
|
||||
}
|
||||
$group = Group::field('group_name')->where('id',$params['group_code'])->findOrEmpty();
|
||||
if($group->isEmpty()){
|
||||
return $this->fail('小组编码错误');
|
||||
}
|
||||
//验证土地图片字段是否是json数组
|
||||
$pic = json_decode($params['pic'],true);
|
||||
if(empty($pic)){
|
||||
return $this->fail('图片数据格式错误');
|
||||
}
|
||||
//创建数据
|
||||
$landRes = Land::create([
|
||||
'user_id' => $this->userId,
|
||||
'title' => $params['title'],
|
||||
'total_area' => $params['area'],
|
||||
'residual_area' => $params['area'],
|
||||
'province_code' => $params['province_code'],
|
||||
'province_name' => $province['province_name'],
|
||||
'city_code' => $params['city_code'],
|
||||
'city_name' => $city['city_name'],
|
||||
'county_code' => $params['county_code'],
|
||||
'county_name' => $county['county_name'],
|
||||
'town_code' => $params['town_code'],
|
||||
'town_name' => $town['town_name'],
|
||||
'village_code' => $params['village_code'],
|
||||
'village_name' => $village['village_name'],
|
||||
'group_code' => $params['group_code'],
|
||||
'group_name' => $group['group_name'],
|
||||
'master_name' => $params['master_name'],
|
||||
'master_phone' => $params['master_phone'],
|
||||
'pic' => $params['pic'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
return $landRes->id ? $this->success('土地添加成功') : $this->fail('土地添加失败');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\land\Land;
|
||||
use app\common\model\plant\Plant;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
|
||||
class PlantController extends BaseApiController
|
||||
{
|
||||
//添加种植
|
||||
public function add(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['land_id','kind','breed','area','user','date','pic','remark']);
|
||||
if(empty($params['land_id']) || empty($params['kind']) || empty($params['breed']) || empty($params['area']) || empty($params['user']) || empty($params['date']) || empty($params['pic'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
if(!strtotime($params['date'])){
|
||||
return $this->fail('日期格式错误');
|
||||
}
|
||||
$pics = json_decode($params['pic'],true);
|
||||
if(empty($pics)){
|
||||
return $this->fail('图片参数格式错误');
|
||||
}
|
||||
//获取土地信息
|
||||
$land = Land::field('residual_area')->where('id',$params['land_id'])->findOrEmpty();
|
||||
if($land->isEmpty()){
|
||||
return $this->fail('土地信息错误');
|
||||
}
|
||||
if($params['area'] > $land['residual_area']){
|
||||
return $this->fail('种植面积超过当前土地可种植面积');
|
||||
}
|
||||
//创建数据
|
||||
Db::transaction(function()use($params,$land) {
|
||||
Plant::create([
|
||||
'land_id' => $params['land_id'],
|
||||
'kind' => $params['kind'],
|
||||
'breed' => $params['breed'],
|
||||
'area' => $params['area'],
|
||||
'user' => $params['user'],
|
||||
'remark' => $params['remark'],
|
||||
'pic' => $params['pic'],
|
||||
'plant_date' => strtotime($params['date']),
|
||||
'status' => 1,
|
||||
'create_time' => time()
|
||||
]);
|
||||
$residual_area = $land['residual_area']-$params['area'];
|
||||
Land::where('id',$params['land_id'])->update(['residual_area'=>$residual_area]);
|
||||
});
|
||||
return $this->success('种植添加成功');
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ namespace app\api\logic;
|
|||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum, YesNoEnum};
|
||||
use app\common\service\{
|
||||
|
@ -44,7 +46,7 @@ class LoginLogic extends BaseLogic
|
|||
* @author 段誉
|
||||
* @date 2022/9/7 15:37
|
||||
*/
|
||||
public static function register(array $params)
|
||||
public static function register(array $params): bool
|
||||
{
|
||||
try {
|
||||
$userSn = User::createUserSn();
|
||||
|
@ -52,15 +54,28 @@ class LoginLogic extends BaseLogic
|
|||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
User::create([
|
||||
Db::transaction(function () use($userSn,$password,$avatar,$params) {
|
||||
$user = User::create([
|
||||
'sn' => $userSn,
|
||||
'avatar' => $avatar,
|
||||
'avatar' => env('project.project_url').'/'.$avatar,
|
||||
'nickname' => '用户' . $userSn,
|
||||
'account' => $params['account'],
|
||||
'account' => $params['mobile'],
|
||||
'mobile' => $params['mobile'],
|
||||
'password' => $password,
|
||||
'channel' => $params['channel'],
|
||||
'channel' => 6,
|
||||
]);
|
||||
|
||||
$admin = Admin::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => '用户' . $userSn,
|
||||
'avatar' => env('project.project_url').'/'.$avatar,
|
||||
'account' => $params['mobile'],
|
||||
'password' => $password
|
||||
]);
|
||||
AdminRole::create([
|
||||
'admin_id' => $admin->id,
|
||||
'role_id' => 1
|
||||
]);
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
|
|
|
@ -70,6 +70,9 @@ class LoginAccountValidate extends BaseValidate
|
|||
|
||||
// 账号密码登录
|
||||
if (LoginEnum::ACCOUNT_PASSWORD == $scene) {
|
||||
if (!isset($data['account'])) {
|
||||
return '请输入账号';
|
||||
}
|
||||
if (!isset($data['password'])) {
|
||||
return '请输入密码';
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
|
@ -31,23 +33,19 @@ class RegisterValidate extends BaseValidate
|
|||
];
|
||||
|
||||
protected $rule = [
|
||||
'channel' => 'require',
|
||||
'account' => 'require|length:3,12|unique:' . User::class . '|regex:register',
|
||||
'mobile' => 'require|mobile|unique:' . User::class,
|
||||
'password' => 'require|length:6,20|regex:password',
|
||||
'password_confirm' => 'require|confirm'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'channel.require' => '注册来源参数缺失',
|
||||
'account.require' => '请输入账号',
|
||||
'account.regex' => '账号须为字母数字组合',
|
||||
'account.length' => '账号须为3-12位之间',
|
||||
'account.unique' => '账号已存在',
|
||||
'mobile.require' => '请输入手机号',
|
||||
'mobile.mobile' => '手机号格式错误',
|
||||
'mobile.unique' => '手机号已存在',
|
||||
'password.require' => '请输入密码',
|
||||
'password.length' => '密码须在6-25位之间',
|
||||
'password.regex' => '密码须为数字,字母或符号组合',
|
||||
'password_confirm.require' => '请确认密码',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致'
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\model\geo\City;
|
||||
use app\common\model\geo\County;
|
||||
use app\common\model\geo\Group;
|
||||
use app\common\model\geo\Province;
|
||||
use app\common\model\geo\Town;
|
||||
use app\common\model\geo\Village;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
|
||||
class GeoController extends BaseLikeAdminController
|
||||
{
|
||||
// 获取省份
|
||||
public function province(): Json
|
||||
{
|
||||
$data = Province::field('province_code,province_name')->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取城市
|
||||
public function city(): Json
|
||||
{
|
||||
$province_code = $this->request->get('province_code');
|
||||
if(empty($province_code)){
|
||||
return $this->fail('请选择省份');
|
||||
}
|
||||
$data = City::field('city_code,city_name')->where('province_code',$province_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取区县
|
||||
public function county(): Json
|
||||
{
|
||||
$city_code = $this->request->get('city_code');
|
||||
if(empty($city_code)){
|
||||
return $this->fail('请选择城市');
|
||||
}
|
||||
$data = County::field('county_code,county_name')->where('city_code',$city_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取镇街
|
||||
public function towns(): Json
|
||||
{
|
||||
$county_code = $this->request->get('county_code');
|
||||
if(empty($county_code)){
|
||||
return $this->fail('请选择区县');
|
||||
}
|
||||
$data = Town::field('town_code,town_name')->where('county_code',$county_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取村社
|
||||
public function villages(): Json
|
||||
{
|
||||
$town_code = $this->request->get('town_code');
|
||||
if(empty($town_code)){
|
||||
return $this->fail('请选择镇街');
|
||||
}
|
||||
$data = Village::field('village_code,village_name')->where('town_code',$town_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取小组
|
||||
public function groups(): Json
|
||||
{
|
||||
$data = Group::field('id as group_code,group_name')->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\action;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Action extends BaseModel
|
||||
{
|
||||
protected $name = 'land_plant_action';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class City extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_city';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class County extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_county';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Group extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_group';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Province extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_province';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Town extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_town';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Village extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_village';
|
||||
}
|
|
@ -1,24 +1,9 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model\land;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Land模型
|
||||
* Class Land
|
||||
|
@ -29,6 +14,4 @@ class Land extends BaseModel
|
|||
|
||||
protected $name = 'land';
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\plant;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Plant extends BaseModel
|
||||
{
|
||||
protected $name = 'land_plant';
|
||||
}
|
|
@ -33,7 +33,8 @@
|
|||
"alibabacloud/client": "^1.5",
|
||||
"rmccue/requests": "^2.0",
|
||||
"w7corp/easywechat": "^6.8",
|
||||
"tencentcloud/sms": "^3.0"
|
||||
"tencentcloud/sms": "^3.0",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
|
Loading…
Reference in New Issue