feat: move miniapp server project

This commit is contained in:
ckaaaa 2025-09-18 10:36:08 +08:00
parent 4a940f28ba
commit 96d9063b13
178 changed files with 9699 additions and 5044 deletions

430
app/controller/Admin.php Normal file
View file

@ -0,0 +1,430 @@
<?php
namespace app\controller;
use think\App;
use app\AdminBaseController;
use think\facade\Log;
use think\exception\ValidateException;
use app\AppCache;
use think\facade\Cache;
use app\Constant;
use Exception;
use think\facade\Config;
class Admin extends AdminBaseController
{
function __construct(
App $app
) {
$this->className = 'V1';
$this->not_check_action_login = [
'test',
'login',
'login_id',
'get_code'
];
parent::__construct($app);
}
public function test() {
json_decode('asdfasdf','');
return ajaxSuccess(json_last_error());
// return ajaxSuccess($this->user_info);
}
public function order_list($current = 1, $pageSize = 10, $order_no = '', $pay_time = '', $buy_type = '', $status = '',$phone='',$name='',$from_user_name='',$create_time=[], $export=0)
{
$user_ids = [];
if($from_user_name){
$list_user = D('user')->where('real_name','LIKE', '%'.$from_user_name.'%')->select();
foreach ($list_user as $one) {
$user_ids[] = $one['id'];
}
}
$model = D('orderx');
$where = [
'deleted' => 0,
];
$model = $model->where($where);
if ($order_no) {
$model = $model->where('order_no', 'LIKE', '%' . $order_no . '%');
}
if ($phone) {
$model = $model->where('phone', 'LIKE', '%' . $phone . '%');
}
if ($name) {
$model = $model->where('name', 'LIKE', '%' . $name . '%');
}
if ($pay_time) {
$model = $model->whereBetween('pay_time', [$pay_time . ' 00:00:00', $pay_time . ' 23:59:59']);
}
if ($buy_type) {
$model = $model->where('buy_type', $buy_type);
}
if ($status) {
$model = $model->where('status', $status);
}else{
$model = $model->where('status', '<>', 'cancel');
}
if($from_user_name){
$model = $model->where('from_user_id','in',$user_ids);
}
if($create_time && count($create_time) == 2) {
$model->where('create_time' ,'>=' ,$create_time[0] . ':00:00:00');
$model->where('create_time' ,'<=' ,$create_time[1] . '23:59:59');
}
$total = 0;
if($export != 1) {
$total = $model->count();
$model->page($current, $pageSize);
}
$_list = $model->order('id DESC')->select();
//
$list = [];
foreach ($_list as $one) {
$user_info = D('user')->where(['id' => $one['from_user_id']])->find();
$one['from_user_name'] = $user_info['real_name'] ?: '';
// $one['phone'] = $user_info['phone'];
$list[] = $one;
}
if($export == 1) {
header('Content-Disposition: attachment; filename=订单列表'. time() . '.xls');
header('Content-Encoding: UTF-8');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
echo '<table>';
$row = [
'订单号','支付金额',
'支付状态','类型','用户名','用户手机号',
'订单时间','支付时间',
// '退款时间','退款金额',
'分销员','分销员id'
];
$v = '<tr><td>' . join("</td><td>", $row) . "</td></tr>";
echo iconv("UTF-8", "GB2312//IGNORE", $v);
foreach ($list as $row) {
$t = [];
$t[] = $row['order_no'];
$t[] = round($row['price']/100,2);
$t[] = Constant::$ORDER_PAY_STAUS[$row['status']]['text'] ?? $row['status'];
$t[] = $row['buy_type'];
$t[] = $row['name'];
$t[] = '\'' . $row['phone'];
$t[] = $row['create_time'];
$t[] = $row['pay_time'];
$t[] = $row['refund_time'];
// $t[] = round($row['refund_money']/100,2);
// $t[] = round($row['refund_inner_money']/100,2);
$t[] = $row['from_user_name'];
$t[] = $row['from_user_id'];
$v ='<tr><td>' . join("</td><td>", $t) . "</td></tr>";
echo iconv("UTF-8", "GB2312//IGNORE", $v);
}
echo '</table>';
}
else {
return ajaxSuccessPage($list, $current, $pageSize, $total);
}
}
public function change_share($id,$is_share) {
D('user')->where(['id'=>$id])->update(['is_share'=>$is_share]);
return ajaxSuccess();
}
public function member_list($current = 1, $pageSize = 10, $is_share='', $real_name='', $create_time=[], $export = 0,$has_phone=0)
{
$model = D('user');
$where = [
'deleted' => 0,
];
$model = $model->where($where);
if ($real_name) {
$model = $model->where('real_name', 'LIKE', '%' . $real_name . '%');
}
if($is_share !== '') {
$model->where(['is_share'=>$is_share]);
}
if($create_time && count($create_time) == 2) {
$model->where('create_time' ,'>=' ,$create_time[0]);
$model->where('create_time' ,'<=' ,$create_time[1]);
}
$total = $model->count();
if($export == 0) {
$model->page($current, $pageSize);
}
$_list = $model->order('id DESC')->select();
$list = [];
foreach ($_list as $one) {
$list[] = $one;
}
if($export == 0) {
return ajaxSuccessPage(c_filter_property_list($list, ['openid','union_id','session_key','sms_code','deleted'], true), $current, $pageSize, $total);
}
else {
// header('Content-Disposition: attachment; filename=会员列表'. time() . '.xlsx');
// header('Content-Encoding: UTF-8');
// header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
// echo '<table>';
// $row = [
// '内部编号','手机号','姓名/昵称',
// '剩余金额','剩余积分','等级积分',
// '会员号','性别','出生年月','自评等级','注册时间'
// ];
// $v = '<tr><td>' . join("</td><td>", $row) . "</td></tr>";
// echo iconv("UTF-8", "GB2312//IGNORE", $v);
// foreach ($list as $row) {
// $t = [];
// $t[] = $row['id'];
// $t[] = '\'' . $row['phone'];
// $t[] = $row['nick_name2'];
// $t[] = round($row['money']/100,2);
// $t[] = $row['score'];
// $t[] = $row['level_score'];
// $t[] = $row['user_no'];
// $t[] = $row['gender2'] == 0 ? '女' :'男';
// $t[] = $row['birth_ym'];
// $t[] = $row['self_level'];
// $t[] = $row['create_time'];
// $v ='<tr><td>' . join("</td><td>", $t) . "</td></tr>";
// echo iconv("UTF-8", "GB2312//IGNORE", $v);
// }
// echo '</table>';
}
}
public function banner_save($id='', $title='',$img='',$action_type='',$action_item='') {
if($id){
D('banner')->where(['id'=>$id])->update([
'title'=> $title,
'img'=>$img,
'action_type'=>$action_type,
'action_item'=>$action_item,
]);
}else{
D('banner')->insert([
'title'=> $title,
'img'=>$img,
'action_type'=>$action_type,
'action_item'=>$action_item,
'create_time'=>c_now(),
]);
}
return ajaxSuccess();
}
public function banner_list($title='',$current = 1, $pageSize = 10) {
$model = D('banner');
$where = ['deleted' => 0];
if ($title) {
$model->where("title LIKE '%" . $title . "%'");
}
$model = $model->where($where);
$total = $model->count();
$list = $model->page($current, $pageSize)->order('id DESC')->select();
return ajaxSuccessPage($list, $current, $pageSize, $total);
}
public function banner_del($id=0) {
D('banner')->where(['id' => $id])->update(['deleted' => 1]);
return ajaxSuccess();
}
public function banner_detail($id=0) {
$one = D('banner')->where(['id' => $id,'deleted'=>0])->find();
return ajaxSuccess($one);
}
//news_admin
public function news_admin_save($id=0, $title='',$content='',$imgs='',$poster=''){
$data = [
'title'=>$title,
'admin_id'=>$this->user_id,
'poster'=> $poster,
'imgs'=>$imgs,
'content'=>$content,
];
if($id){
D('news')->where(['id'=>$id])->update($data);
}else{
$data['create_time'] = c_now();
D('news')->insert($data);
}
return ajaxSuccess();
}
public function news_admin_del($id=0) {
D('news')->where(['id' => $id])->update(['deleted' => 1]);
return ajaxSuccess();
}
// public function news_admin_recommend($id=0,$recommend=0) {
// D('news_admin')->where(['id' => $id])->update(['recommend' => $recommend,'recommend_time'=>c_now()]);
// return ajaxSuccess();
// }
// public function news_admin_banner($id=0,$banner=0) {
// D('news_admin')->where(['id' => $id])->update(['banner' => $banner,'banner_time'=>c_now()]);
// return ajaxSuccess();
// }
public function news_admin_detail($id=''){
$detail = D('news')->where(['id'=>$id,'deleted'=>0])->find();
$user = D('admin')->where(['id'=>$detail['admin_id']])->find();
$user = c_filter_property($user,['name','id']);
return ajaxSuccess([
'detail'=>$detail,
'user'=>$user,
]);
}
public function news_admin_list($current = 1, $pageSize = 10,$title='') {
$model = D('news');
$where = ['deleted' => 0];
if ($title) {
$model->where("title LIKE '%" . $title . "%'");
}
$model = $model->where($where);
$total = $model->count();
$list = $model->page($current, $pageSize)->order('id DESC')->select();
return ajaxSuccessPage($list, $current, $pageSize, $total);
}
//
public function dashborad() {
$re=[];
$re['today_order_nums'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->where('create_time', '>=', date('Y-m-d', time()) . ' 00:00:00')->count();
$re['today_order_price'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->where('create_time', '>=', date('Y-m-d', time()) . ' 00:00:00')->sum('price');
$re['all_order_nums'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->count();
$re['all_order_price'] = D('orderx')->where(['status'=>'payed','deleted'=>0])->sum('price');
return ajaxSuccess($re);
}
public function user_save($data) {
$data = c_filter_property($data, [
'id', 'name',
'username', 'role',
'status', 'password',
]);
$in_admin = D('admin')->where(['deleted' => 0, 'username' => $data['username']])->find();
if (!empty($in_admin) && $in_admin['id'] != ($data['id'] ?? '')) {
return ajaxFail('用户名已存在,请更换', -1);
}
$_data = [];
$_data = array_merge($_data, $data);
$this->log_notice($_data, 'user_save', 'user_save');
if ($_data['password'] ?? '') {
$_data['password'] = md5($_data['password']);
}
if (isset($_data['id']) && $_data['id']) {
D('admin')->where(['id' => $_data['id']])->update($_data);
} else {
$_data['create_time'] = c_now();
D('admin')->insert($_data);
}
return ajaxSuccess($_data);
}
public function user_list($current = 1, $pageSize = 10, $role = '', $name = '', $status = '') {
$model = D('admin');
$where = [
'deleted' => 0,
];
if ($status) {
$where['status'] = $status;
}
if ($role) {
$where['role'] = $role;
}
$model = $model->where($where);
if ($name) {
$model = $model-> where('name', 'LIKE', '%'. $name. '%');
}
$total = $model->count();
$list = $model->page($current, $pageSize)->order('id DESC')->select();
return ajaxSuccessPage(c_filter_property_list($list, ['password', 'deleted'], true), $current, $pageSize, $total);
}
public function upload() {
$file = request()->file('file');
if ($file) {
try {
// validate([
// 'file' => [
// 'fileSize' => (50 * 1024 * 1024),
// 'fileExt' => ['png', 'jpg', 'xls', 'xlsx', 'pdf', 'doc', 'docx', 'odf'],
// ]
// ])->check(['file' => $file]);
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
return ajaxSuccess([
'path' => '/uploads/' . (str_replace('\\', '/', $savename)),
]);
} catch (ValidateException $e) {
// 上传失败获取错误信息
return ajaxFail($e->getMessage(), -2);
}
}
return ajaxFail('未选择上传文件,请重试', -3);
}
public function change_passwd($new_passwd){
D('admin')->where(['id'=>$this->user_id])->update(['password'=>md5($new_passwd)]);
return ajaxSuccess();
}
public function login_id($id) {
$user = D('admin')->where(['id' => $id, 'deleted' => 0, 'status' => 'stay'])->find();
$cookie_id = a_encode($user['id'] . '|' . time(), Config::get('app.ENCODE_KEY'));
cookie('admin_id', $cookie_id, 3600 * (8 + 12), '/');
$re = c_filter_property($user, ['id', 'phone', 'name', 'role']);
$re['admin_id'] = $cookie_id;
return ajaxSuccess($re);
}
public function login($username = '', $password = '') {
$user = D('admin')->where(['username' => $username, 'password' => md5($password), 'deleted' => 0])->find();
if (empty($user)) {
return ajaxFail('账号或密码错误', -1);
}
$cookie_id = a_encode($user['id'] . '|' . time(), Config::get('app.ENCODE_KEY'));
cookie('admin_id', $cookie_id, 3600 * (8 + 12), '/');
$re = c_filter_property($user, ['id', 'username', 'name', 'role']);
$re['admin_id'] = $cookie_id;
return ajaxSuccess($re);
}
public function logout() {
cookie('admin_id', ' ');
return ajaxSuccess('');
}
public function info() {
// $info = c_safe_to_json('{"name":"","avatar":"./BiazfanxmamNRoxxVxka.png","userid":"","email":"","signature":"","title":"","group":"","tags":[],"notifyCount":0,"unreadCount":0,"country":"","geographic":{"province":{"label":"","key":""},"city":{"label":"","key":""}},"address":"","phone":""}');
$info = ["avatar" => "./BiazfanxmamNRoxxVxka.png"];
$user = $this->user_info;
// print_r($user);
// print_r($info);
// print_r($this->user_id);
$info['name'] = $user['name'];
$info['userid'] = $user['id'];
$info['phone'] = '';
$info['role'] = $user['role'];
return ajaxSuccess($info);
}
public function all_enums() {
$all_enums = D('config')->select();
$re = ['$all_enums'=>$all_enums];
foreach ($all_enums as $one) {
$re[$one['k']] = c_safe_to_json($one['v'], $one['v']);
}
$user_list = D('admin')->where(['deleted' => 0])->select();
$re['admin_list'] = c_filter_property_list($user_list, ['id', 'name', 'role', 'username']);
//
return ajaxSuccess($re);
}
public function enum_save($value = '', $type = '') {
D('config')->where(['k' => $type])->update(['v' => $value]);
return ajaxSuccess($value);
}
}

24
app/controller/Index.php Normal file
View file

@ -0,0 +1,24 @@
<?php
namespace app\controller;
use think\App;
use app\BaseController;
use think\facade\Env;
class Index extends BaseController
{
function __construct(App $app)
{
$this->check_actions = [
'#index' => []
];
parent::__construct($app);
}
public function index()
{
$re = intval('y12') - 1;
return ajaxSuccess($re);
}
}

230
app/controller/Sys.php Normal file
View file

@ -0,0 +1,230 @@
<?php
namespace app\controller;
use think\App;
use app\BaseController;
use Exception;
use think\facade\Cache;
use app\Constant;
use think\facade\Config;
use think\facade\Db;
use app\service\ToolService;
class Sys extends BaseController
{
protected $service_tool = null;
function __construct(
App $app,
ToolService $toolService
) {
$this->service_tool = $toolService;
$this->className = 'api.Sys';
$this->ignore_log_params = true;
parent::__construct($app);
}
/*
# if ! pgrep -f zhihuitb_test > /dev/null; then
# echo "zhihuitb_test stoped, to start";
# nohup sh ./zhihuitb_test.sh > /dev/null 2>&1 &
# else
# echo "zhihuitb_test.sh runing";
# fi
*/
// 通用分割
public function auto_deal_type_SegmentHDCommonImage() {
$list = D('orders')->where(['deal_type' => 'SegmentHDCommonImage', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
print_r($list);
foreach ($list as $one) {
if ($one['deal_status'] == 'ing') continue;
if ($one['deal_status'] == 'init') {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
$deal_params = c_safe_to_json($one['deal_params']);
$root_dir = root_path();
$filepath = $root_dir . 'public' . $deal_params['path'];
$imageUrl = $this->service_tool->tongYongFenGe($filepath);
if ($imageUrl) {
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $imageUrl, 'deal_status' => 'done']);
} else {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
}
}
}
if (count($list) == 0) {
echo 'No Task';
}
}
// VIP 购买
public function auto_deal_type_vip() {
$list = D('orders')->where(['deal_type' => 'vip', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init'])->order('id ASC')->select();
foreach ($list as $one) {
if ($one['deal_status'] == 'init') {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
$deal_params = c_safe_to_json($one['deal_params']);
$num = $deal_params['num'];
$order_no = $one['order_no'];
$user_id = $one['user_id'];
$user = D('user')->where(['id' => $user_id])->find();
if (empty($user)) {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
$this->log_error('用户不存在:' . $user_id . ';order_no:'.$order_no, 'auto_deal_vip', 'auto_deal_vip');
continue;
}
$now_expire_time = $user['vip_expire_time'];
if (!$now_expire_time) {
$now_expire_time = time();
} else {
$now_expire_time = strtotime($now_expire_time);
}
$now_expire_time = $now_expire_time + $num * 30 * 24 * 3600;
$now_expire_time = date('Y-m-d', $now_expire_time) . ' 23:59:59';
D('user')->where(['id' => $user_id])->update(['vip_expire_time' => $now_expire_time]);
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $now_expire_time, 'deal_status' => 'done']);
}
}
if (count($list) == 0) {
echo 'No Task';
}
}
// 一寸照异步返回
public function auto_deal_type_SegmentBody_01_cb($order_no) {
$root_dir = root_path();
$out_dir = $root_dir . 'public';
$out_path = '/output/SegmentBody_01/' . $order_no . '.jpg';
$filepath = $out_dir . $out_path;
if (file_exists($filepath)) {
D('orders')->where(['order_no' => $order_no])->update(['deal_result' => $out_path, 'deal_status' => 'done']);
} else {
D('orders')->where(['order_no' => $order_no])->update(['deal_status' => 'fail']);
}
return ajaxSuccess();
}
// 一寸照
public function auto_deal_type_SegmentBody_01() {
$list = D('orders')->where(['deal_type' => 'SegmentBody', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
foreach ($list as $one) {
if ($one['deal_status'] == 'ing') continue;
if ($one['deal_status'] == 'init') {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
$deal_params = c_safe_to_json($one['deal_params']);
$root_dir = root_path();
$path = $root_dir . 'public' . $deal_params['path'];
$color = $deal_params['color'];
$order_no = $one['order_no'];
$out_dir = $root_dir . 'public';
$out_path = '/output/SegmentBody_01/' . $order_no . '.jpg';
// 运行python
echo 'python3 ./idcard/idcard.py -p ' . $path .' '. $color . ' ' . $out_dir . $out_path;
// 执行回调结果
echo "\n";
echo "curl 'http://127.0.0.1/index.php/sys/auto_deal_type_SegmentBody_01_cb?order_no=" . $order_no . "' -H 'Host:zhihuitb.zhonganonline.top'";
// echo 'python3'.c_json_encode($deal_params) . '_' . $order_id;
// $imageUrl = $this->service_tool->tuPianShangSe($deal_params['path']);
// if($imageUrl) {
// D('orders')->where(['id'=>$one['id']])->update(['deal_result'=>$imageUrl,'deal_status'=>'done']);
// } else {
// D('orders')->where(['id'=>$one['id']])->update(['deal_status'=>'fail']);
// }
}
}
if (count($list) == 0) {
echo 'No Task';
}
}
// 照片上色
public function auto_deal_type_ColorizeImage_01() {
$list = D('orders')->where(['deal_type' => 'ColorizeImage', 'deleted' => 0, 'status' => 'payed'])->where('deal_status', 'IN', ['init', 'ing'])->order('id ASC')->limit(2)->select();
print_r($list);
foreach ($list as $one) {
if ($one['deal_status'] == 'ing') continue;
if ($one['deal_status'] == 'init') {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'ing']);
$deal_params = c_safe_to_json($one['deal_params']);
$root_dir = root_path();
$filepath = $root_dir . 'public' . $deal_params['path'];
$imageUrl = $this->service_tool->tuPianShangSe($filepath);
if ($imageUrl) {
D('orders')->where(['id' => $one['id']])->update(['deal_result' => $imageUrl, 'deal_status' => 'done']);
} else {
D('orders')->where(['id' => $one['id']])->update(['deal_status' => 'fail']);
}
}
}
if (count($list) == 0) {
echo 'No Task';
}
}
public function timer_cancel_order() {
D('orderx')->where(['status' => 'wait_pay'])->where('create_time', '<=', c_now(time() - 30 * 60))->update(['status' => 'cancel']);
return ajaxSuccess();
}
public function clear_access_token() {
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
Cache::set($cache_key, '');
return '';
}
/**
* 定时获取access_token
* test ok
* http://testwx.yunyoumg.com/index.php/api/sys/access_token
*/
public function access_token() {
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
$env = env('app.envName', 'prod');
if ($env == 'prod') {
$cache_a_k = Cache::get($cache_key);
// c_debug($cache_a_k);
if ($cache_a_k) {
if ($cache_a_k['time'] + 3600 >= time()) {
return ajaxSuccess($cache_a_k);
}
}
c_debug('重新获取小程序ac了');
$appid = Config::get('app.APPID');
$secret = Config::get('app.SECERT_KEY');
$data = curl_get_https("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret);
$data = json_decode($data, true);
if (!array_key_exists('errorCode', $data)) {
Cache::set($cache_key, [
'access_token' => $data['access_token'],
'time' => time(),
], $data['expires_in'] * 1);
return ajaxSuccess($data);
}
return ajaxFail($data, -1);
}
// $data = curl_get_https('https://www.yunyoumg.com/api/Collection/getMini');
// $data = curl_get_https('https://mini.yunyoumg.com/index.php/api/sys/get_access_token');
// $data = json_decode($data, true);
// if (!array_key_exists('errorCode', $data)) {
// Cache::set($cache_key, [
// 'access_token' => $data['data']['accessToken'],
// 'time' => time(),
// ]);
// return ajaxSuccess($data['data']['accessToken']);
// }
Cache::set($cache_key, $data['model']);
}
public function get_access_token() {
$cache_key = Constant::$CACHE_ACCESS_TOKEN;
$ac = Cache::get($cache_key);
// echo json_encode([
// 'data'=>[
// 'accessToken'=>$ac['access_token'],
// ]
// ]);
// exit();
return ajaxSuccess($ac);
}
public function test($t) {
$this->log_notice($t, 'feishu', 'feishu');
return ajaxSuccess();
}
}

602
app/controller/V1.php Normal file
View file

@ -0,0 +1,602 @@
<?php
namespace app\controller;
use think\App;
use app\BaseController;
use think\facade\Log;
use think\exception\ValidateException;
use app\AppCache;
use think\facade\Cache;
use app\Constant;
use Exception;
use think\facade\Config;
use app\service\ToolService;
class V1 extends BaseController
{
protected $service_tool = null;
function __construct(
App $app,
ToolService $toolService
) {
$this->service_tool = $toolService;
$this->check_actions = [
];
$this->className = 'V1';
$this->not_check_action_login = [
'test',
'pay_notify',
'wx_login',
];
parent::__construct($app);
}
public function goods_list() {
$list = D('goods')->where(['deleted' => 0])->order('sort ASC')->select();
return ajaxSuccess($list);
}
public function test() {
// $root_dir = root_path();
// $filepath = $root_dir . '/public/uploads/' . 'zpss.jpg';
// $re = $this->service_tool->tuPianShangSe($filepath);
$re = $this->mark_order_yiCunZhao(2, '/uploads/ycz.jpg', 'white');
return ajaxSuccess($re);
}
public function mark_order_vip($goods_id = '', $num = 1) {
$deal_params = ['num' => $num];
$goods = D('goods')->where(['id' => $goods_id, 'deleted' => 0])->find();
if (empty($goods)) {
return ajaxFail('不存在的服务', -1);
}
$order_no = s_order_id_render('Z');
$order = [
'user_id' => $this->user_id,
'goods_id' => $goods_id,
// 'from_user_id' => $share['from_user_id'],
'create_time' => c_now(),
'status' => 'wait_pay',
'order_no' => $order_no,
'price' => $goods['price'] * $num,
'deal_type' => $goods['deal_type'],
'funct_name' => $goods['funct_name'],
'deal_params' => c_json_encode($deal_params),
];
D('orders')->insert($order);
return ajaxSuccess(['order_no' => $order_no]);
}
public function mark_order_tongYongFenGe($goods_id='',$path='') {
$deal_params = ['path' => $path];
return $this->mark_order_base($goods_id, $deal_params);
}
// color: red blue white;
public function mark_order_yiCunZhao($goods_id = '', $path = '', $color = '') {
$deal_params = ['path' => $path,
'color' => $color];
return $this->mark_order_base($goods_id, $deal_params);
}
public function mark_order_zhaopianshangse($goods_id = '', $path = '') {
$deal_params = ['path' => $path];
return $this->mark_order_base($goods_id, $deal_params);
}
private function mark_order_base($goods_id, $deal_params) {
// 是否是vip
$is_vip = strtotime($this->user_info['vip_expire_time'] ?: c_now()) > time();
if (!$is_vip) {
$goods_free_use_limit = D('config')->where(['k' => 'goods_free_use_limit'])->value('v');
$find_user_use = D('user_use_cnt')->where(['goods_id' => $goods_id, 'user_id' => $this->user_id])->find();
$use_cnt = 0;
if($find_user_use) {
$use_cnt = $find_user_use['use_cnt'];
}else{
D('user_use_cnt')->insert(['goods_id' => $goods_id, 'user_id' => $this->user_id, 'use_cnt'=>0]);
}
if ($use_cnt >= $goods_free_use_limit) {
return ajaxFail('免费次数使用结束,请先充值', -1);
}
}
$goods = D('goods')->where(['id' => $goods_id, 'deleted' => 0])->find();
if (empty($goods)) {
return ajaxFail('不存在的服务', -2);
}
$order_no = s_order_id_render('Z');
$order = [
'user_id' => $this->user_id,
'goods_id' => $goods_id,
// 'from_user_id' => $share['from_user_id'],
'create_time' => c_now(),
'status' => 'wait_pay',
'order_no' => $order_no,
'price' => $goods['price'],
'deal_type' => $goods['deal_type'],
'funct_name' => $goods['funct_name'],
'deal_params' => c_json_encode($deal_params),
];
D('orders')->insert($order);
D('user_use_cnt')->where(['goods_id' => $goods_id, 'user_id' => $this->user_id])->inc('use_cnt');
$this->pay_notify($order_no);
return ajaxSuccess(['order_no' => $order_no]);
}
public function order_list($page = 1) {
$list = D('orders')->where(['deleted' => 0, 'user_id' => $this->user_id])->where(['status' => 'payed'])->page($page, 10)->order('id DESC')->select();
return ajaxSuccess($list);
}
public function config_one($k) {
$v = D('config')->where(['k' => $k])->value('v');
$v = c_safe_to_json($v, $v);
return ajaxSuccess($v);
}
public function configs($ks = '') {
$model = D('config');
if ($ks) {
$model->where('k', 'in', $ks);
}
$all_enums = $model->select();
$re = [];
foreach ($all_enums as $one) {
$re[$one['k']] = c_safe_to_json($one['v'], $one['v']);
}
//
return ajaxSuccess($re);
}
public function my() {
$info = $this->user_info;
if ($info['is_share']) {
$info['price_sum'] = D('orderx')->where(['status' => 'payed'])->where(['from_user_id' => $this->user_id])->sum('price');
$info['share_cnt'] = D('share')->where(['from_user_id' => $this->user_id])->count();
$info['share_view_cnt'] = D('share')->where(['from_user_id' => $this->user_id])->sum('view_cnt');
}
$show_vip_link = $info['is_share'] ? true : false;
if (!$show_vip_link) {
if (D('orderx')->where(['status' => 'payed'])->where(['user_id' => $this->user_id])->find()) {
$show_vip_link = true;
}
}
$info['show_vip_link'] = $show_vip_link;
$info['payed_vip_link'] = D('config')->where(['k' => 'payed_vip_link'])->value('v');
return ajaxSuccess($info);
}
public function set_name($name = '') {
D('user')->where(['id' => $this->user_id])->update(['real_name' => $name]);
return ajaxSuccess();
}
public function bind_auth_phone($code = '') {
$row_user = D('user')->where([
'id' => $this->user_id,
])->find();
$cache_a_k = Cache::get(Constant::$CACHE_ACCESS_TOKEN);
$qdata = [
'code' => $code,
];
$re_data = curl_post_https('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' . $cache_a_k['access_token'], json_encode($qdata));
$this->log_notice([$re_data], '授权手机号返回', 'bind_auth_phone');
// $session_key = $row_user['session_key'];
// $data = decrypt_wx_data($encrypted_data, $iv, $session_key);
// if (is_int($data) && $data < 0) {
// return ajaxFail('数据解析失败', -1);
// }
// /*
// {
// "phoneNumber": "13580006666",
// "purePhoneNumber": "13580006666",
// "countryCode": "86",
// "watermark":
// {
// "appid":"APPID",
// "timestamp": TIMESTAMP
// }
// }
// */
// //更新数据
// $pure_phone_number = $data['purePhoneNumber'];
// $country_code = $data['countryCode'];
$re_data_json = c_safe_to_json($re_data);
if (isset($re_data_json['errcode']) && $re_data_json['errcode'] == 0) {
$pure_phone_number = $re_data_json['phone_info']['purePhoneNumber'];
$country_code = $re_data_json['phone_info']['countryCode'];
D('user')->where([
'id' => $this->user_id,
])->update([
'phone' => $pure_phone_number,
'phone_country_code' => $country_code,
]);
return ajaxSuccess($pure_phone_number);
}
return ajaxFail('获取手机号失败', -1);
}
public function static_data_get($id) {
$row = D('static_data')->where(['id' => $id])->find();
return ajaxSuccess($row);
}
/**
*小程序上传文件
*/
public function wx_upload() {
$file = request()->file('img_file');
if ($file) {
try {
validate([
'img_file' => [
'fileSize' => (20 * 1024 * 1024),
'fileExt' => ['png', 'jpg', 'jpeg'],
]
])->check(['img_file' => $file]);
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
return ajaxSuccess([
'path' => '/uploads/' . str_replace('\\', '/', $savename),
]);
} catch (ValidateException $e) {
// 上传失败获取错误信息
$this->log_notice($e->getMessage(), '上传失败获取错误信息', 'wx_upload');
return ajaxFail($e->getMessage(), -2);
}
}
$file = request()->file('audio_file');
if ($file) {
try {
validate([
'audio_file' => [
'fileSize' => (20 * 1024 * 1024),
'fileExt' => ['mp3'],
]
])->check(['audio_file' => $file]);
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
return ajaxSuccess([
'path' => '/uploads/' . str_replace('\\', '/', $savename),
]);
} catch (ValidateException $e) {
// 上传失败获取错误信息
return ajaxFail($e->getMessage(), -2);
}
}
$file = request()->file('video_file');
if ($file) {
try {
validate([
'video_file' => [
'fileSize' => (200 * 1024 * 1024),
'fileExt' => ['mp4'],
]
])->check(['video_file' => $file]);
$savename = \think\facade\Filesystem::disk('public')->putFile(date('Y-m-d'), $file, 'md5');
return ajaxSuccess([
'path' => '/uploads/' . str_replace('\\', '/', $savename),
]);
} catch (ValidateException $e) {
// 上传失败获取错误信息
return ajaxFail($e->getMessage(), -3);
}
}
return ajaxFail('未选择上传文件,请重试', -3);
}
public function wx_login($code) {
if ($code != 'test') {
$data = code_2_session($code);
if ($data == null) {
return ajaxFail('授权失败', -1);
}
} else {
$data['openid'] = 'o3CkR7ecDQlsBfAW88Cmjin4YkmI';
$data['unionid'] = 'oV_Fvs_X63XiA1UDc2Bvx1YbD3bk';
$data['session_key'] = 'HBwb0sNhajpzzgM4nuMt6w==';
}
$openid = $data['openid'];
$unionid = $data['unionid'] ?? '';
$session_key = $data['session_key'];
$row_user = D('user')->where('openid', $openid)->where(['deleted' => 0])->find();
if (empty($row_user)) {
D('user')->insert([
'union_id' => $unionid,
'openid' => $openid,
'session_key' => $session_key,
'create_time' => date('Y-m-d H:i:s', time()),
]);
$user_id = D('user')->getLastInsID();
}
//update
else {
$user_id = $row_user['id'];
$update = [
'session_key' => $session_key,
// 'union_id'=>$unionid,
];
if ($unionid) {
$update['union_id'] = $unionid;
}
D('user')->where('openid', $openid)->update($update);
}
// c_debug('有人登录了:' . $user_id);
return ajaxSuccess([
// 'union_id' => $unionid,
'user_id' => a_encode($user_id . '|' . time()),
'openid' => $openid,
'phone' => empty($row_user) ? '' : $row_user['phone'],
]);
}
public function login_id($id=0) {
$row_user = D('user')->where(['id'=>$id])->find();
setcookie('user_id', a_encode($id . '|' . time()));
return ajaxSuccess([
// 'union_id' => $unionid,
'user_id' => a_encode($id . '|' . time()),
'openid' => $row_user['openid'],
'phone' => empty($row_user) ? '' : $row_user['phone'],
]);
}
public function fetch_order($order_no) {
$order = D('orders')->where([
'order_no' => $order_no,
'user_id' => $this->user_id,
])->find();
return ajaxSuccess(c_filter_property($order, ['deleted', 'pay_wx_data', 'need_auto_refund', 'deal_type', 'deal_params', 'deal_result'], true));
}
public function pay_order($order_no = '') {
$order = D('orders')->where([
'order_no' => $order_no,
// 'user_id' => $this->user_id,
])->find();
if (empty($order)) {
return ajaxFail('不存在的订单', -2);
}
$price = intval($order['price']);
// $debug = false;
// $debug = Config::get('app.APP_DEBUG');
// if ($debug) {
// $price = 1;
// }
$appid = Config::get('app.APPID');
$body = '商城订单' . $order_no;
$mch_id = Config::get('app.MCH_ID');
$pay_url = Config::get('app.PAY_NOTIFY_URL_SHOP');
$key = Config::get('app.PAY_KEY');
$nonce_str = '0123456789';
$openid = $this->user_info['openid'];
$create_ip = '127.0.0.1';
$need_encode_str = "appid=" . $appid
. "&body=" . $body
. "&mch_id=" . $mch_id
. "&nonce_str=" . $nonce_str
. "&notify_url=" . $pay_url
. "&openid=" . $openid
. "&out_trade_no=" . $order_no
. "&sign_type=MD5"
. "&spbill_create_ip=" . $create_ip
. "&total_fee=" . $price
. "&trade_type=JSAPI"
. "&key=" . $key;
$this->log_notice($need_encode_str, '$need_encode_str', 'pay_order');
$sign = strtoupper(md5($need_encode_str));
$xml = '<xml>'
. '<appid>' . $appid . '</appid>'
. '<body><![CDATA[' . $body . ']]></body>'
. '<mch_id>' . $mch_id . '</mch_id>'
. '<nonce_str>' . $nonce_str . '</nonce_str>'
. '<notify_url>' . $pay_url . '</notify_url>'
. '<openid>' . $openid . '</openid>'
. '<out_trade_no>' . $order_no . '</out_trade_no>'
. '<sign_type>MD5</sign_type>'
. '<spbill_create_ip>' . $create_ip . '</spbill_create_ip>'
. '<total_fee>' . $price . '</total_fee>'
. '<trade_type>JSAPI</trade_type>'
. '<sign>' . $sign . '</sign>'
. '</xml>';
$res_map = \s_make_wx_order($xml);
// Log::write(json_encode($res_map), 'notice');
$this->log_notice($res_map, '请求支付参数', 'pay_order');
if ($res_map['return_code'] == 'SUCCESS') {
$timeStamp = time();
$paySign = md5('appId=' . $appid
. '&nonceStr=' . $nonce_str
. '&package=prepay_id=' . $res_map['prepay_id']
. '&signType=MD5'
. '&timeStamp=' . $timeStamp
. '&key=' . $key);
return ajaxSuccess([
'timeStamp' => '' . $timeStamp,
'nonceStr' => $nonce_str,
'package' => 'prepay_id=' . $res_map['prepay_id'],
'signType' => 'MD5',
'paySign' => $paySign,
]);
}
return ajaxFail('调用支付接口失败', -3);
}
// 微信支付回调
public function pay_notify($_test_success_order_no = '') {
$str = file_get_contents('php://input');
if ($_test_success_order_no) {
$str = '';
}
// 模拟支付成功
if (!$str && $_test_success_order_no) {
$map = ['out_trade_no' => $_test_success_order_no,
'系统默认支付成功0元或测试单'];
} else {
$this->log_notice($str, '支付通知', 'pay_notify');
$map = c_read_xml_to_map($str);
if (empty($map) || !isset($map['out_trade_no'])) {
$this->log_warn($map['out_trade_no'], '错误的支付消息', 'pay_notify');
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[错误的消息]]></return_msg></xml>';
exit();
}
}
$order_no = $map['out_trade_no'];
$notify_return = 0;
$order_detail = D('orders')->where(['order_no' => $order_no])->find(); // 查询包含已删除
if (empty($order_detail)) {
$notify_return = -1;
}
if ($order_detail['status'] != 'wait_pay') {
// 只记录,不失败
$this->log_warn($map['out_trade_no'], '订单状态不正确', 'pay_notify');
// $this->service_any->sendqywx_test($map['out_trade_no'] . '订单状态不正确','');
if ($order_detail['status'] != 'payed') {
D('orders')->where(['id' => $order_detail['id']])->update(['need_auto_refund' => 1]);
}
}
//超时支付和正常支付都算能支付
D('orders')->where(['id' => $order_detail['id'], 'deleted' => 0])->update(['status' => 'payed', 'pay_time' => c_now(), 'pay_wx_data' => $str]);
if ($notify_return == -1) {
if ($_test_success_order_no) {
return ajaxFail([$order_no], '订单ID不存在', 'pay_notify');
}
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[订单ID不存在]]></return_msg></xml>';
} else if ($notify_return == 0) {
if ($_test_success_order_no) {
return ajaxSuccess();
}
echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
}
if ($_test_success_order_no) {
return ajaxFail([$order_no], '支付通知', 'pay_notify');
}
}
//
public function ______unuse_function_start______() {}
public function notice_list() {
$list = D('notice')->where(['delete' => 0])
->where('start_time', '<=', date('Y-m-d H:i:s', time()))
->where('end_time', '>=', date('Y-m-d H:i:s', time()))->select();
return ajaxSuccess(c_filter_property_list($list, ['id', 'title', 'content', 'create_time']));
}
public function notice_deital($id) {
$detail = D('notice')->where(['id' => $id, 'delete' => 0])->find();
return ajaxSuccess(\c_filter_property($detail, ['delete', 'start_time', 'end_time'], true));
}
public function mark_order_info($order_no, $name = '', $phone = '', $position = '') {
D('orderx')->where(['order_no' => $order_no])->update([
'name' => $name,
'phone' => $phone,
'position' => $position,
]);
return ajaxSuccess();
}
public function make_order($share_id) {
$share = D('share')->where(['id' => $share_id, 'deleted' => 0])->find();
if (empty($share)) {
return ajaxFail('链接已失效,请联系客服');
}
if ($share['expire_time']) {
if ($share['expire_time'] <= c_now()) {
return ajaxFail('购买链接已过期,请重新联系客服');
}
}
$order_no = s_order_id_render('P');
$order = [
'user_id' => $this->user_id,
'share_id' => $share_id,
'from_user_id' => $share['from_user_id'],
'create_time' => c_now(),
'status' => 'wait_pay',
'order_no' => $order_no,
'price' => $share['price'],
'buy_type' => $share['buy_type'],
];
D('orderx')->insert($order);
return ajaxSuccess(['order_no' => $order_no]);
}
public function get_share($id) {
$data = D('share')->where(['id' => $id, 'deleted' => 0])->find();
// if(strtotime($data['expire_time']) >= time()) {
// return ajaxFail('支付链接已超时,请联系客服');
// }
// $v = D('config')->where(['k' => 'buy_types'])->value('v');
// $data['buy_types'] = c_safe_to_json($v, $v);
// $v = D('config')->where(['k' => 'tip_before_pay'])->value('v');
// $data['tip_before_pay'] = c_safe_to_json($v, $v);
// $v = D('config')->where(['k' => 'tip_after_pay'])->value('v');
// $data['tip_after_pay'] = c_safe_to_json($v, $v);
return ajaxSuccess($data);
}
public function view_share($id) {
D('share')->where(['id' => $id, 'deleted' => 0])->inc('view_cnt')->update();
return ajaxSuccess();
}
public function del_share($id) {
D('share')->where(['id' => $id])->update(['deleted' => 1]);
return ajaxSuccess();
}
public function share_link_list($page = 1, $pageSize = 10) {
$list = D('share')->where(['from_user_id' => $this->user_id, 'deleted' => 0])->where('expire_time', '>=', c_now())->page($page, $pageSize)->select();
return ajaxSuccess($list);
}
public function create_share($price, $expireDate, $buy_type = '') {
if (!$this->user_info['is_share']) {
return ajaxFail('您暂无分销权限', -1);
}
$data = [
'from_user_id' => $this->user_id,
'price' => $price * 100,
'expire_time' => $expireDate . ' 23:59:59',
'create_time' => c_now(),
'title' => '推荐您购买' . $buy_type,
'img' => 'http://cdn.zhonganonline.top/liiistem/static/liii_icon.png',
'buy_type' => $buy_type,
];
D('share')->insert($data);
$id = D('share')->getLastInsID();
$data['id'] = $id;
// $data['path'] =
return ajaxSuccess($data);
}
public function mark($id, $remark = '') {
$one = D('orderx')->where(['id' => $id, 'from_user_id' => $this->user_id])->find();
if (empty($one)) {
return ajaxFail('不存在的内容', -1);
}
D('orderx')->where(['id' => $id])->update(['remark' => $remark]);
return ajaxSuccess();
}
public function share_list($page = 1, $status = '') {
$model = D('orderx')->where(['from_user_id' => $this->user_id]);
if ($status) {
$model->where(['status' => $status]);
} else {
$model->where('status', 'IN', ['payed', 'wait_pay']);
}
$list = $model->page($page, 10)->order('id DESC')->select();
return ajaxSuccess($list);
}
public function banner_list() {
$where = ['deleted' => 0];
$list = D('banner')->where($where)->order('id DESC')->select();
return ajaxSuccess($list);
}
public function news_list($page = 1, $pageSize = 10) {
$where = ['deleted' => 0,
'status' => 1];
$model = D('news')->order('id DESC')->where($where);
$list = $model->page($page, $pageSize)->select();
return ajaxSuccess($list);
}
public function news_detail($id = '') {
$detail = D('news')->where(['id' => $id, 'deleted' => 0])->find();
if (!$detail) {
return ajaxFail('数据不存在', -1);
}
$detail['view_cnt'] = $detail['view_cnt'] + 1;
D('news')->where(['id' => $id, 'deleted' => 0])->update(['view_cnt' => $detail['view_cnt']]);
return ajaxSuccess([
'detail' => $detail,
]);
}
}