SchoolPhysicalExamination/application/KitchenScale/controller/app/Usercenter.php

185 lines
8.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\KitchenScale\controller\app;
use think\Db;
class Usercenter extends Base{
protected $code_time = 50;
// protected $token_time = 2592000;//30天的秒数
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
protected $page_num = 20;
protected $reedaw_db_msg = [
'zhanghao'=>'app_account_number',//账号表
'juese'=>'app_user_data',//角色表
];
protected $kitchenscale_db_msg = [
'cookbook'=>'app_user_cookbook',//菜谱表
'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
'uploadimg'=>'app_user_upload_img',//图片素材表
'foodlist1'=>'app_food_type_one',//食材列表1
'foodlist2'=>'app_food_type_two',//食材列表2
'foodlist3'=>'app_food_type_three',//食材列表3
'collect_list'=>'app_user_collect_list',//点赞表
'banner'=>'app_banner_data',//banner
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 获取用户收藏点赞列表(OK)
public function get_user_collect_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('page', $data)){
return $this->msg(10001,'page is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005,'page type is error');
}
$return_data = $this->get_user_collect_list_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["flie"] = $e->getFile();
// $logContent["line"] = $e->getLine();
// $logContent['all_content'] = "异常信息:\n";
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
// $logContent['all_content'] .= "接口: get_default_config\n";
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// $this->record_api_log($data, $logContent, null);
// return $this->msg(99999);
// }
}
// 我的菜谱
public function get_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1]){
// try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('page', $data)){
return $this->msg(10001,'page is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005,'page type is error');
}
$return_data = $this->get_my_cookbook_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["flie"] = $e->getFile();
// $logContent["line"] = $e->getLine();
// $logContent['all_content'] = "异常信息:\n";
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
// $logContent['all_content'] .= "接口: get_default_config\n";
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// $this->record_api_log($data, $logContent, null);
// return $this->msg(99999);
// }
}
#######################################################################action#######################################################################
#######################################################################action#######################################################################
#######################################################################action#######################################################################
public function get_user_collect_list_action($data){
// 获取账号下信息以及用户信息
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
if($user_data<=0){
return $this->msg(10005,'账号信息错误');
}
$search_sql_str = "a.token = '".$data['token']."' AND a.is_del = 0";
if(!array_key_exists('search_data', $data)){
$data['search_data'] = "";
}else{
if($data['search_data'] === ""){
$data['search_data'] = "";
}else{
$data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')";
}
}
$search_sql_str = $search_sql_str.$data['search_data'];
// "a.token = 'asdasdasdasda' AND a.is_del = 0 AND b.title LIKE '%鱼%' OR b.describe_data LIKE '%鱼%'";
$cfc = Db::connect('cfc_db');
$content_num = $cfc->table($this->kitchenscale_db_msg['collect_list'])
->alias('a')
->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
->where($search_sql_str)
->count();
$page_total = ceil($content_num/$this->page_num);;
$collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])
->alias('a')
->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT')
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
->where($search_sql_str)
->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
->page($data['page'],$this->page_num)
->select();
return $this->msg([
'page_now'=>$data['page'],
'page_total'=>$page_total,
'content_list'=>$collect_list
]);
}
public function get_my_cookbook_action($data){
// 获取账号下信息以及用户信息
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
if($user_data<=0){
return $this->msg(10005,'账号信息错误');
}
$cfc = Db::connect('cfc_db');
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('b')
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
->where(['b.create_user_token'=>$data['token'],'b.is_del'=>0])
->count();
$page_total = ceil($content_num/$this->page_num);;
$collect_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('b')
->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT')
->where(['b.create_user_token'=>$data['token'],'b.is_del'=>0])
->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname")
->page($data['page'],$this->page_num)
->select();
return $this->msg([
'page_now'=>$data['page'],
'page_total'=>$page_total,
'content_list'=>$collect_list
]);
}
}