机构API后台接口

This commit is contained in:
15090180611 2025-01-24 16:37:49 +08:00
parent 45d8d1425a
commit 03352c14aa
10 changed files with 835 additions and 15 deletions

View File

@ -75,6 +75,17 @@ class Apirule extends Backend
if (!$params['ismenu'] && !$params['pid']) {
$this->error(__('The non-menu rule must have parent'));
}
// //自己不能是自己的上级
// if ($params['pid'] == $params['id']) {
// $this->error(__('The parent can not be itself'));
// }
// //不能形成递归的关系环路:自己的子孙是自己的儿子
// $childrenIds = Tree::instance()->init(collection(ManystoreApiAuthRule::select())->toArray())->getChildrenIds($params['pid']);
// if (in_array($params['pid'], $childrenIds)) {
// $this->error(__('Can not change the parent to child'));
// }
$result = $this->model->validate()->save($params);
if ($result === false) {
$this->error($this->model->getError());
@ -103,6 +114,12 @@ class Apirule extends Backend
if (!$params['ismenu'] && !$params['pid']) {
$this->error(__('The non-menu rule must have parent'));
}
//自己不能是自己的上级
if ($params['pid'] == $row['id']) {
$this->error(__('The parent can not be itself'));
}
if ($params['pid'] != $row['pid']) {
$childrenIds = Tree::instance()->init(collection(ManystoreApiAuthRule::select())->toArray())->getChildrenIds($row['id']);
if (in_array($params['pid'], $childrenIds)) {

View File

@ -2,6 +2,7 @@
namespace app\admin\controller\manystore;
use app\admin\controller\school\classes\VisitDistribution;
use app\manystore\model\ManystoreAuthRule;
use app\common\controller\Backend;
use fast\Tree;
@ -103,16 +104,23 @@ class Rule extends Backend
if (!$params['ismenu'] && !$params['pid']) {
$this->error(__('The non-menu rule must have parent'));
}
//自己不能是自己的上级
if ($params['pid'] == $params['id']) {
$this->error(__('The parent can not be itself'));
}
if ($params['pid'] != $row['pid']) {
$childrenIds = Tree::instance()->init(collection(ManystoreAuthRule::select())->toArray())->getChildrenIds($row['id']);
if (in_array($params['pid'], $childrenIds)) {
$this->error(__('Can not change the parent to child'));
}
}
//这里需要针对name做唯一验证
$ruleValidate = \think\Loader::validate('ManystoreAuthRule');
$ruleValidate->rule([
'name' => 'require|format|unique:ManystoreAuthRule,name,' . $row->id,
'name' => 'require|format|unique:ManystoreAuthRule,name,' . $row['id'],
]);
$result = $row->validate()->save($params);
if ($result === false) {

View File

@ -18,6 +18,15 @@
<input type="text" class="form-control" id="name" name="row[name]" data-placeholder-node="{:__('Node tips')}" data-placeholder-menu="{:__('Menu tips')}" value="" data-rule="required" />
</div>
</div>
<div class="form-group">
<label for="asname" class="control-label col-xs-12 col-sm-2">{:__('路由唯一namevue-router')}:</label>
<div class="col-xs-12 col-sm-8">
<input type="text" class="form-control" id="asname" name="row[asname]" data-placeholder-node="{:__('Node tips')}" data-placeholder-menu="{:__('Menu tips')}" value="" data-rule="required" />
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -18,6 +18,14 @@
<input type="text" class="form-control" id="name" name="row[name]" data-placeholder-node="{:__('Node tips')}" data-placeholder-menu="{:__('Menu tips')}" value="{$row.name|htmlentities}" data-rule="required" />
</div>
</div>
<div class="form-group">
<label for="asname" class="control-label col-xs-12 col-sm-2">{:__('路由唯一namevue-router')}:</label>
<div class="col-xs-12 col-sm-8">
<input type="text" class="form-control" id="asname" name="row[asname]" data-placeholder-node="{:__('Node tips')}" data-placeholder-menu="{:__('Menu tips')}" value="{$row.asname|htmlentities}" data-rule="required" />
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -4,6 +4,7 @@ namespace app\common\model\school\classes;
use app\common\library\Virtual;
use app\common\model\BaseModel;
use app\common\model\dyqc\ManystoreShop;
use think\Model;
use traits\model\SoftDelete;
@ -69,12 +70,6 @@ class Teacher extends BaseModel
public function user()
{
return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function manystore()
{
return $this->belongsTo('app\admin\model\Manystore', 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0);
@ -83,12 +78,19 @@ class Teacher extends BaseModel
public function shop()
{
return $this->belongsTo('app\admin\model\manystore\Shop', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo(ManystoreShop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function detail($id){
$self = $this->get($id,["shop"]);
$self["shop"]->visible(['name']);
$self = $this->get($id,["shop","user","manystore"]);
// $self["shop"]->visible(['name']);
return $self;
}

View File

@ -2,10 +2,12 @@
namespace app\common\model\school\classes;
use app\common\model\BaseModel;
use app\common\model\dyqc\ManystoreShop;
use think\Model;
class Verification extends Model
class Verification extends BaseModel
{
@ -54,12 +56,117 @@ class Verification extends Model
public function shop()
{
return $this->belongsTo('app\admin\model\manystore\Shop', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo(ManystoreShop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function detail($id){
$self = $this->get($id,["shop","user","manystore"]);
// $self["shop"]->visible(['name']);
return $self;
}
/**得到基础条件
* @param $status
* @param null $model
* @param string $alisa
*/
public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false)
{
if (!$model) {
$model = new static;
if ($alisa&&!$with) $model = $model->alias($alisa);
}
if ($alisa) $alisa = $alisa . '.';
$tableFields = (new static)->getTableFields();
foreach ($tableFields as $fields)
{
if(in_array($fields, ['status']))continue;
// if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
if (isset($whereData[$fields]) && $whereData[$fields]){
if(is_array($whereData[$fields])){
$model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]);
}else{
$model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
}
}
}
if (isset($whereData['status']) && $whereData['status']) $model = $model->where("{$alisa}status", 'in', $whereData['status']);
if (isset($whereData['not_status']) && $whereData['not_status']) $model = $model->where("{$alisa}status", 'not in', $whereData['not_status']);
// if (isset($whereData['keywords'])&&$whereData['keywords']) $model = $model->where("{$alisa}name|{$alisa}id", '=', $whereData['keywords']);
if (isset($whereData['time'])&&$whereData['time']){
$model = $model->time(["{$alisa}createtime",$whereData['time']]);
}
if (isset($whereData['user_id']) && $whereData['user_id']) $model = $model->where("{$alisa}user_id", '=', $whereData['user_id']);
if (isset($whereData['shop_id']) && $whereData['shop_id']) $model = $model->where("{$alisa}shop_id", 'in', $whereData['shop_id']);
if (isset($whereData['keywords'])&&$whereData['keywords']){
if($with){
$model = $model->where( function($query) use($whereData,$alisa,$with){
$query = $query->where("{$alisa}classes_lib_ids|{$alisa}user_id", 'like', "%". $whereData['keywords']."%");
if(in_array('user',$with)){
$query = $query->whereOr("user.nickname|user.realname|user.mobile", 'like', "%". $whereData['keywords']."%");
}
if(in_array('shop',$with)){
$query = $query->whereOr("shop.name|shop.address|shop.address_detail|shop.tel", 'like', "%". $whereData['keywords']."%");
}
if(in_array('manystore',$with)){
$query = $query->whereOr("manystore.username|manystore.nickname|manystore.email", 'like', "%". $whereData['keywords']."%");
}
});
}else{
$model = $model->where("{$alisa}classes_lib_ids|{$alisa}user_id", 'like', "%". $whereData['keywords']."%");
}
}
return $model;
}
public static function allList($page, $limit,$params=[]){
$with_field = [
'base'=>['*'],
'user'=>['nickname',"realname","mobile","avatar"],
'shop'=>['name','address',"address_detail","tel","logo","image"],
'manystore'=>['username','nickname',"email","user_id","avatar"],
];
$alisa = (new self)->getWithAlisaName();
$sort = "{$alisa}.id desc";
// if(!empty($params['status'])){
// $params['status'] = '1';
// }
return (new self)->getBaseList($params, $page, $limit,$sort,$with_field);
}
}

View File

@ -883,7 +883,44 @@ class Order extends BaseModel
}
if (isset($whereData['status'])) $model = $model->where("{$alisa}status", 'in', $whereData['status']);
if (isset($whereData['not_status'])) $model = $model->where("{$alisa}status", 'not in', $whereData['not_status']);
if (isset($whereData['keywords'])&&$whereData['keywords']) $model = $model->where("{$alisa}order_no|{$alisa}pay_no|{$alisa}code", '=', $whereData['keywords']);
// if (isset($whereData['keywords'])&&$whereData['keywords']) $model = $model->where("{$alisa}order_no|{$alisa}pay_no|{$alisa}code", '=', $whereData['keywords']);
if (isset($whereData['keywords'])&&$whereData['keywords']){
if($with){
// 'user'=>['nickname','mobile','avatar','realname'],
// 'base'=>['*'],
// 'shop'=>['*'],
// 'detail'=>['*'],
// 'evaluate'=>['*'],
// 'serviceorder'=>['*']
$model = $model->where( function($query) use($whereData,$alisa,$with){
$query = $query->where("{$alisa}order_no|{$alisa}pay_no|{$alisa}code", '=', $whereData['keywords']);
if(in_array('user',$with)){
$query = $query->whereOr("user.nickname|user.realname|user.mobile", 'like', "%". $whereData['keywords']."%");
}
if(in_array('shop',$with)){
$query = $query->whereOr("shop.name|shop.address|shop.address_detail|shop.tel", 'like', "%". $whereData['keywords']."%");
}
if(in_array('manystore',$with)){
$query = $query->whereOr("manystore.username|manystore.nickname|manystore.email", 'like', "%". $whereData['keywords']."%");
}
if(in_array('detail',$with)){
$query = $query->whereOr("detail.title|detail.address|detail.address_detail", 'like', "%". $whereData['keywords']."%");
}
});
}else{
$model = $model->where("{$alisa}order_no|{$alisa}pay_no|{$alisa}code", '=', $whereData['keywords']);
}
}
if (isset($whereData['time'])&&$whereData['time']){
$model = $model->time($whereData['time']);
@ -940,6 +977,32 @@ class Order extends BaseModel
public static function allShopList($page, $limit,$params=[]){
$with_field = [
'user'=>['nickname','mobile','avatar','realname'],
'base'=>['*'],
'shop'=>['*'],
'detail'=>['*'],
'evaluate'=>['*'],
'serviceorder'=>['*']
];
$CANCEL = '-3';
$NOPAY = '0';
$PAYED = '3';
$REFUND = '6';
$FINISH = '9';
$IN_SERVICE = '4';
$alisa = (new self)->getWithAlisaName();
$sort = "field({$alisa}.status,'{$NOPAY}','{$PAYED}','{$FINISH}','{$REFUND}','{$IN_SERVICE}','{$CANCEL}') asc,{$alisa}.id desc";
$serch_where = $params;
// if($type)$serch_where['type'] = $type;
return (new self)->getBaseList($serch_where, $page, $limit,$sort,$with_field);
}
public static function baseCount($where = []){
$CANCEL = '-3';

View File

@ -89,7 +89,7 @@ class OrderLog extends BaseModel
public function order()
public function classesorder()
{
return $this->belongsTo(Order::class, 'classes_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
@ -141,4 +141,19 @@ class OrderLog extends BaseModel
return $log;
}
public static function allList($page, $limit,$params=[]){
$with_field = [
'classesorder'=>['order_no',"pay_no","manystore_id","shop_id","classes_lib_id","classes_order_detail_id"],
'base'=>['*'],
];
$alisa = (new self)->getWithAlisaName();
$sort = "{$alisa}.id desc";
$serch_where = $params;
// if($type)$serch_where['type'] = $type;
return (new self)->getBaseList($serch_where, $page, $limit,$sort,$with_field);
}
}

View File

@ -0,0 +1,231 @@
<?php
namespace app\manystoreapi\controller;
use app\common\controller\ManystoreApiBase;
use app\common\model\school\classes\ClassesSpec;
use app\common\model\school\classes\order\Order as OrderModel;
/**
* 机构API后台课程订单
*/
class ClassesOrder extends ManystoreApiBase
{
protected $model = null;
/**
* 初始化操作
* @access protected
*/
public function _initialize()
{
$this->model = new OrderModel;
parent::_initialize();
//判断登录用户是否是员工
}
/**
* @ApiTitle( 订单详情)
* @ApiSummary(订单详情)
* @ApiMethod(GET)
* @ApiParams(name = "id", type = "int",required=true,description = "订单id或订单号")
* @ApiReturn({
*
*})
*/
public function detail(){
$id = $this->request->get('id/d','');
if(empty($id)){
$this->apierror(__('缺少必要参数'));
}
try {
$res = OrderModel::getDetail($id);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->apierror($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->apisuccess('获取成功', ['detail' => $res]);
}
/**
* @ApiTitle( 我的订单列表接口)
* @ApiSummary(我的订单列表接口)
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "status", type = "string",required=false,description = "状态搜索条件:-3=已取消,0=待支付,3=使用中,4=售后中,6=已退款,9=已完成")
* @ApiParams(name = "classes_lib_id", type = "int",required=false,description = "课程id")
* @ApiParams(name = "has_evaluate", type = "int",required=false,description = "是否评价:默认0全部 1查已评价 2查未评价")
* @ApiReturn({
*
*})
*/
public function order_list()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$params=[
"shop_id"=>$this->auth->shop_id,
];
$page = $this->request->get('page/d', 0); //页数
$limit = $this->request->get('limit/d', 0); //条数
$keywords = $this->request->get('keywords/s', ''); //搜索关键字
$status = $this->request->get('status/s', ''); //搜索关键字
$classes_lib_id = $this->request->get('classes_lib_id/s', ''); //搜索关键字
$has_evaluate = $this->request->get('has_evaluate/d', 0); //搜索关键字
// $type = $this->request->get('type/s', ''); //筛选学员和教练单
$params["keywords"] = $keywords;
$params["status"] = $status;
$params["classes_lib_id"] = $classes_lib_id;
$params["has_evaluate"] = $has_evaluate;
try{
//当前申请状态
$res = $this->model::allShopList($page, $limit,$params);
// if($user_id =='670153'){
// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql());
// }
}catch (\Exception $e){
$this->apierror($e->getMessage());
}
$this->apisuccess('查询成功', $res);
}
/**
* @ApiTitle( 我的订单列表数量统计)
* @ApiSummary(我的订单列表数量统计)
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "classes_lib_id", type = "int",required=false,description = "课程id")
* @ApiParams(name = "has_evaluate", type = "int",required=false,description = "是否评价:默认0全部 1查已评价 2查未评价")
* @ApiReturn({
*
*})
*/
public function order_count()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$params=[
"shop_id"=>$this->auth->shop_id,
];
$keywords = $this->request->get('keywords/s', ''); //搜索关键字
// $status = $this->request->get('status/s', ''); //搜索关键字
$classes_lib_id = $this->request->get('classes_lib_id/s', ''); //搜索关键字
$has_evaluate = $this->request->get('has_evaluate/d', 0); //搜索关键字
// $type = $this->request->get('type/s', ''); //筛选学员和教练单
$params["keywords"] = $keywords;
// $params["status"] = $status;
$params["classes_lib_id"] = $classes_lib_id;
$params["has_evaluate"] = $has_evaluate;
try{
//当前申请状态
$res = $this->model::baseCount($params);
// if($user_id =='670153'){
// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql());
// }
}catch (\Exception $e){
$this->apierror($e->getMessage());
}
$this->apisuccess('查询成功', $res);
}
/**
* @ApiTitle( 课程订单取消)
* @ApiSummary(课程订单取消)
* @ApiMethod(POST)
* @ApiParams(name = "ids", type = "int",required=true,description = "课程订单id")
* @ApiReturn({
*
*})
*/
public function cancel($ids = ''){
$param = $this->request->param();
if($this->request->isPost()){
try{
if(isset($param['ids']))$ids = $param['ids'];
//设置模拟资格
$model = (new \app\common\model\school\classes\order\Order);
$model->cancel($ids,0,true,'shop',$this->auth->id,true);
}catch (\Exception $e){
$this->apierror($e->getMessage());
}
$this->apisuccess('取消成功!');
}
}
/**
* @ApiTitle( 课程订单发起售后)
* @ApiSummary(课程订单发起售后)
* @ApiMethod(POST)
* @ApiParams(name = "id", type = "int",required=true,description = "课程订单id")
* @ApiParams(name = "reason", type = "int",required=true,description = "申请售后原因")
* @ApiParams(name = "price", type = "int",required=true,description = "退款金额")
* @ApiReturn({
*
*})
*/
public function after_sales($ids = ""){
if($this->request->isPost())
{
try{
$params = $this->request->post();
$classes_order = $params["id"];
$reason = $params["reason"];
$model = (new \app\common\model\school\classes\order\ServiceOrder());
$remark = "机构端管理员帮忙下售后单";
$order = $model->afterSales($classes_order,$reason,$remark,'shop',$this->auth->id,true);
$price = $params["price"];
$status = "yes";
$reject_reason = "";
$reject_images = "";
$model = (new \app\common\model\school\classes\order\ServiceOrder());
$model->shopConfirmation($order["order_no"],$status,$price,$reject_reason,$reject_images,0,true,'shop',$this->auth->id,true);
}catch (\Exception $e){
$this->apierror($e->getMessage());
}
$this->apisuccess("执行成功");
}
}
}

View File

@ -0,0 +1,360 @@
<?php
namespace app\manystoreapi\controller;
use app\common\controller\ManystoreApiBase;
use app\common\model\manystore\UserAuth;
use app\common\model\school\classes\Verification as Verificationmodel;
use app\common\model\User;
use app\manystore\model\Manystore;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 机构API后台机构核销员接口
*/
class Verification extends ManystoreApiBase
{
// protected $noNeedLogin = ["detail",'people','spec',"teacher_list"];
// protected $noNeedRight = '*';
protected $model = null;
/**
* 初始化操作
* @access protected
*/
public function _initialize()
{
$this->model = new Verificationmodel;
parent::_initialize();
//判断登录用户是否是员工
}
/**
* @ApiTitle( 机构核销员详情)
* @ApiSummary(机构核销员详情)
* @ApiMethod(GET)
* @ApiParams(name = "id", type = "int",required=true,description = "机构核销员id")
* @ApiReturn({
*
*})
*/
public function detail(){
$id = $this->request->get('id/d','');
if(empty($id)){
$this->apierror(__('缺少必要参数'));
}
try {
$res = $this->model->detail($id);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->apierror($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->apisuccess('获取成功', ['detail' => $res]);
}
/**
* @ApiTitle( 机构核销员列表(取决于搜索条件))
* @ApiSummary(机构核销员列表(取决于搜索条件))
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "status", type = "string",required=false,description = "状态:1=开启,2=关闭")
* @ApiParams(name = "shop_id", type = "string",required=false,description = "机构店铺id")
* @ApiParams(name = "user_id", type = "string",required=false,description = "教师用户id")
* @ApiReturn({
*
*})
*/
public function verification_list()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$params=[
"shop_id"=>$this->auth->shop_id,
];
$page = $this->request->get('page/d', 0); //页数
$limit = $this->request->get('limit/d', 0); //条数
$params['keywords'] = $this->request->get('keywords/s', ''); //搜索关键字
$params['status'] = $this->request->get('status/s', ''); //搜索关键字
$params['shop_id'] = $this->request->get('shop_id/d', ''); //搜索关键字
$params['user_id'] = $this->request->get('user_id/d', ''); //搜索关键字
// $type = $this->request->get('type/s', ''); //筛选学员和教练单
try{
//当前申请状态
$res = $this->model::allList($page, $limit,$params);
// if($user_id =='670153'){
// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql());
// }
}catch (\Exception $e){
$this->apierror($e->getMessage());
}
$this->apisuccess('查询成功', $res);
}
protected function updateCheck($id,$params=[],$row=null){
}
/**
* @ApiTitle( 核销员删除)
* @ApiSummary(核销员删除)
* @ApiMethod(POST)
* @ApiParams(name = "ids", type = "int",required=true,description = "核销员id")
* @ApiReturn({
* 微信小程序码图片流
*})
*/
public function del($ids = "")
{
if (!$this->request->isPost()) {
$this->apierror(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
if ($ids) {
$pk = $this->model->getPk();
if($this->shopIdAutoCondition){
$this->model->where(array('shop_id'=>SHOP_ID));
}
$list = $this->model->where($pk, 'in', $ids)->select();
foreach ($list as $item) {
$this->updateCheck($item->id);
}
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->apierror($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->apierror($e->getMessage());
}
if ($count) {
$this->apisuccess();
} else {
$this->apierror(__('No rows were deleted'));
}
}
$this->apierror(__('Parameter %s can not be empty', 'ids'));
}
protected function update_check(&$params,$row=null)
{
$shop_id = SHOP_ID;
$manystore = Manystore::where("shop_id", $shop_id)->find();
if (!$manystore) {
$this->apierror("店铺不存在");
}
$params["manystore_id"] = $manystore["id"];
$params["shop_id"] = $shop_id;
$user = User::where("id|nickname|realname|mobile", $params["user_id"])->find();
if(!$user) $this->apierror("未找到用户请先让用户登录小程序再提交表单".$params["user_id"]);
try {
\app\common\model\manystore\UserAuth::auth(0,$shop_id,$user["id"],0,'shop',$this->auth->id);
}catch (\Exception $e){
}
//如果开启了检测用户授权,则检测用户是否授权
if(config("site.shop_auth_user_check")){
if(!UserAuth::authcheck($shop_id,$user["id"])) $this->apierror("用户未授权当前机构!请先让用户授权同意您再操作!");
}
$params["user_id"] = $user["id"];
$user_id = $params["user_id"];
//修改
if($row){
//用户已是其他的教师(搜索)
$teacher_user = $this->model->where("user_id",$user_id)->where("id","<>",$row["id"])->find();
if($teacher_user){
$this->apierror("用户已存在或已是其他授权机构核销员!");
}
}else{
//新增
//用户已是教师(搜索)
$teacher_user = $this->model->where("user_id",$user_id)->find();
if($teacher_user){
$this->apierror("用户已存在或已是其他授权机构核销员!");
}
}
}
/**
* @ApiTitle( 核销员添加)
* @ApiSummary(核销员添加)
* @ApiMethod(POST)
* @ApiParams(name = "user_id", type = "int",required=true,description = "核销员前台用户id")
* @ApiParams(name = "status", type = "int",required=true,description = "状态:1=开启,2=关闭")
* @ApiReturn({
*
*})
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post();
if ($params) {
if($this->storeIdFieldAutoFill && STORE_ID ){
$params['store_id'] = STORE_ID;
}
if($this->shopIdAutoCondition && SHOP_ID){
$params['shop_id'] = SHOP_ID;
}
try {
$this->update_check($params,$row=null);
} catch (ValidateException|PDOException|Exception $e) {
$this->apierror($e->getMessage());
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$this->update_check($params,$row=null);
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->apierror($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->apierror($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->apierror($e->getMessage());
}
if ($result !== false) {
$this->apisuccess();
} else {
$this->apierror(__('No rows were inserted'));
}
}
$this->apierror(__('Parameter %s can not be empty', ''));
}
}
/**
* @ApiTitle( 核销员编辑)
* @ApiSummary(核销员编辑)
* @ApiMethod(POST)
* @ApiParams(name = "ids", type = "int",required=true,description = "核销员id")
* @ApiParams(name = "user_id", type = "int",required=true,description = "核销员前台用户id")
* @ApiParams(name = "status", type = "int",required=true,description = "状态:1=开启,2=关闭")
* @ApiReturn({
*
*})
*/
public function edit($ids = null)
{
$ids = $ids ? $ids : $this->request->post("ids");
if ($this->request->isPost()) {
if($this->shopIdAutoCondition){
$this->model->where(array('shop_id'=>SHOP_ID));
}
$row = $this->model->where(array('id'=>$ids))->find();
if (!$row) {
$this->apierror(__('No Results were found'));
}
$params = $this->request->post();
if ($params) {
$result = false;
try {
$this->update_check($params,$row);
} catch (ValidateException|PDOException|Exception $e) {
$this->apierror($e->getMessage());
}
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$this->update_check($params,$row);
$result = $row->allowField(true)->save($params);
$classesLibs = \app\common\model\school\classes\ClassesLib::where( ['teacher_id'=>$row["id"]])->select();
foreach ($classesLibs as $classesLib){
$classesLib->user_id = $row["user_id"];
$classesLib->save();
//执行课程订单更新
\app\common\model\school\classes\ClassesLib::update_classes($classesLib["id"]);
}
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->apierror($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->apierror($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->apierror($e->getMessage());
}
if ($result !== false) {
$this->apisuccess("更新成功");
} else {
$this->apierror(__('No rows were updated'));
}
}
$this->apierror(__('Parameter %s can not be empty', ''));
}
}
}