0 ? $day . '天' : '';
$hour = floor(($remain_time % (3600 * 24)) / 3600);
$hour = $hour > 0 ? $hour . '小时' : '';
if ($is_hour && $is_minutes) {
$minutes = floor((($remain_time % (3600 * 24)) % 3600) / 60);
$minutes = $minutes > 0 ? $minutes . '分钟' : '';
return $day . $hour . $minutes;
}
if ($hour) {
return $day . $hour;
}
return $day;
}
function getTime($second)
{
$day = floor($second / (3600 * 24));
$second = $second % (3600 * 24);//除去整天之后剩余的时间
$hour = floor($second / 3600);
$second = $second % 3600;//除去整小时之后剩余的时间
$minute = floor($second / 60);
$second = $second % 60;//除去整分钟之后剩余的时间
//返回字符串
return $hour . '小时' . $minute . '分' . $second . '秒';
}
function getDay($second)
{
$day = floor($second / (3600 * 24));
$second = $second % (3600 * 24);//除去整天之后剩余的时间
$hour = floor($second / 3600);
$second = $second % 3600;//除去整小时之后剩余的时间
$minute = floor($second / 60);
$second = $second % 60;//除去整分钟之后剩余的时间
//返回字符串
return $day;
}
/**
* get请求
* @param $url
* @param string $msg
* @return mixed
*/
function requestGet($url, $msg = '')
{
// 1. 初始化一个cURL会话
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//执行并获取HTML文档内容
$response = curl_exec($ch);
// 4. 释放cURL句柄,关闭一个cURL会话
curl_close($ch);
return $response;
}
//获取全图片地址 $image_data
function image_path($image_data)
{
if (empty($image_data)) {
return $image_data;
}
if (strpos($image_data, '|') !== false) {
$image_res = explode('|', $image_data);
} elseif (strpos($image_data, ',') !== false) {
$image_res = explode(',', $image_data);
} else {
$image_res = array($image_data);
}
return $image_res;
}
function get_order_sn()
{
$order_id_main = date('YmdHis') . rand(10000000, 99999999);
$order_id_len = strlen($order_id_main);
$order_id_sum = 0;
for ($i = 0; $i < $order_id_len; $i++) {
$order_id_sum += (int)(substr($order_id_main, $i, 1));
}
$osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100, 2, '0', STR_PAD_LEFT);
return $osn;
}
//通过服务类型,手机型号获取价格
function get_goods_price($goods_id, $serve_type_id, $phone_type_id = 0)
{
$goods_info = Db::name('store_goods')->field('id,cate_id')->where('status', 1)->where('id', $goods_id)->where('is_deleted', 0)->find();
if (empty($goods_info)) {
$this->error('服务信息有误');
}
$data = array('code' => 1, 'msg' => '获取成功');
if ($goods_info['cate_id'] == 0) { //金刚区服务
if (empty($phone_type_id)) {
$data['code'] = 0;
$data['msg'] = '参数错误';
}
$serve_type_name = Db::name('store_goods_type')->where('id', $serve_type_id)->value('spec_name');
$phone_type_name = Db::name('store_goods_type')->where('id', $phone_type_id)->value('spec_name');
$goods_price = Db::name('store_goods_list')->where('goods_id', $goods_id)->where('goods_spec', 'like', '%' . $serve_type_name . '%')->where('goods_spec', 'like', '%' . $phone_type_name . '%')->value('price_selling');
} else {
$serve_type_name = Db::name('store_goods_type')->where('id', $serve_type_id)->value('spec_name');
$goods_price = Db::name('store_goods_list')->where('goods_id', $goods_id)->where('goods_spec', 'like', '%' . $serve_type_name . '%')->value('price_selling');
}
if ($goods_price <= 0) {
$data['code'] = 0;
$data['msg'] = '价格信息有误';
}
$data['price'] = $goods_price;
return $data;
}
//邮箱推送
function mail_push($mail_str, $order_id)
{
//查询订单信息
$order_info = Db::name('store_order')->field('goods_id,serve_type,client_tel,client_qq,price_amount,describe,create_at')->where('id', $order_id)->find();
$order_info['goods_title'] = Db::name('store_goods')->where('id', $order_info['goods_id'])->value('title');
$body = "服务类目:" . $order_info['goods_title'] . "
服务类型:" . $order_info['serve_type'] . "
用户手机:" . $order_info['client_tel'] . "
用户QQ:" . $order_info['client_qq'] . "
订单金额:" . $order_info['price_amount'] . "
附加信息:" . $order_info['describe'] . "
下单时间:" . $order_info['create_at'];
require_once env('root_path') . '/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
//需要设置对应的region名称,如华东1(杭州)设为cn-hangzhou,新加坡Region设为ap-southeast-1,澳洲Region设为ap-southeast-2。
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "LTAI5tSMNtYuD3TdEkM65fyp", "lcmARfziFDS4PUJ0K7AKTf3Ytl3Z8O");
$client = new DefaultAcsClient($iClientProfile);
$request = new Dm\SingleSendMailRequest();
$request->setAccountName("feisu@tsguangsu.com");
$request->setFromAlias("飞速");
$request->setAddressType(1);
$request->setTagName("feisu");
$request->setReplyToAddress("true");
$request->setToAddress($mail_str);
$request->setSubject("新订单通知,请及时处理");
$request->setHtmlBody($body);
try {
$client->getAcsResponse($request);
} catch (ClientException $e) {
print_r($e->getErrorCode());
print_r($e->getErrorMessage());
} catch (ServerException $e) {
print_r($e->getErrorCode());
print_r($e->getErrorMessage());
}
}
///**
// * 获取Token
// */
//function UserToken()
//{
// $token = Request::instance()->header('authorization');
//
// $verify = TokenUtils::verify($token);
// return \app\model\User::where('id', $verify['data']['uid'])->find();
//}
/**
* 判断等级
* * @param int $experience
*/
function Grade(int $experience)
{
if ($experience <= 500) return 'lv1';
if ($experience > 500 && $experience <= 550) return 'lv2';
if ($experience > 550 && $experience <= 1300) return 'lv3';
if ($experience > 1300 && $experience <= 4500) return 'lv4';
if ($experience > 4500) return 'lv5';
}
/**
* 实名认证
* * @param string $name
* * @param string $id_num
*/
function authentication(string $name, string $id_num)
{
// $name = input('name');
// $id_num = input('id_num');
if (empty($name) || empty($id_num)) {
$this->error('参数错误');
}
$host = "https://99numa.market.alicloudapi.com";
$path = "/dsp-aliyun/api/validate/idcard";
$method = "POST";
$appcode = "f131dd012f244a7f8d5cecd04e7a36d5";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//需要自行安装UUID,需要给X-Ca-Nonce的值生成随机字符串,每次请求不能相同
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$uuidStr = '';
for ($i = 0; $i < 10; $i++) {
$uuidStr .= $chars[mt_rand(0, strlen($chars) - 1)];
}
$name = urlencode($name);
array_push($headers, "X-Ca-Nonce:" . $uuidStr);
$querys = "chName=" . $name . "&idNum=" . $id_num;
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$res = curl_exec($curl);
$res = json_decode($res, true);
if ($res['respCode'] == '00000000') {
return true;
} else {
return false;
}
}
/**
* 获取小程序码
* */
function qr_code(int $uid)
{
$scene = $uid;
$app = Factory::miniProgram(Config('mini_program'));
$response = $app->app_code->getUnlimit($scene, [
'page' => 'pages/index/index',
'width' => 600,
'check_path' => false,
'env_version' => 'trial'
]);
$root_path = env('root_path') . 'public';
$path = '/qr_code/' . date('YmdH');
$code_path = $root_path . $path;
$code_name = md5(time() . rand('10000', '99999')) . '.png';
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$filename = $response->saveAs($code_path, $code_name);
if ($filename) {
return 'https://' . $_SERVER['SERVER_NAME'] . $path . '/' . $code_name;
} else {
return false;
}
} else {
return false;
}
}
/**
* 根据金额返回经验和积分和佣金
* * @param int $transactionPrice
* * @param int $id
*/
function ComputationalExperience(int $transactionPrice, int $id)
{
$user = Db::name('release_user')->find($id);
if ($user['grade'] == 'lv0') {
$info = [
'experience' => 0,
'integral' => 0,
'grade' => 'lv0'
];
return $info;
}
if ($user['grade'] == 'lv1') {
$info = [
'experience' => $transactionPrice / 10,
'integral' => $transactionPrice,
'grade' => Grade($user['experience'] + $transactionPrice / 10)
];
return $info;
} else {
$release_member = Db::name('release_member')->where('grade', $user['grade'])->find();
$info['experience'] = $release_member['basic_experience'] * $release_member['empirical_ratio'];
$info['integral'] = $release_member['basic_integral'] * $release_member['integral_magnification'];
$info['grade'] = Grade($user['experience'] + $info['experience']);
}
return $info;
}
/**
* 根据金额返回佣金
* * @param int $favorablePrice
* * @param int $id
* * @param int $orderId
*/
function commission(int $id, int $favorablePrice, int $orderId)
{
// dump(NewUserCommission($orderId, $favorablePrice)[0]);
// return RecommenderCommission($id, $orderId, $favorablePrice);
return [
'userMoney' => NewUserCommission($orderId, $favorablePrice),
'superiorMoney' => RecommenderCommission($id, $orderId, $favorablePrice),
];
}
/**
* 新用户下单获取佣金
* * @param int $favorablePrice
* * @param int $orderId
*/
function NewUserCommission(int $orderId, int $favorablePrice)
{
$proportion = Db::name('release_proportion')->find(1);
$orderInfo = Db::name('release_order')->find($orderId);
$user_info = Db::name('release_user')->find($orderInfo['user_id']);
// $result = \app\model\Order::where([
// 'payment_status' => 4,
// 'user_id' => $orderInfo['user_id']
// ])->min('id');
$time = time() - strtotime($user_info['create_time']);
$result = $time / 86400 < 60;
if ($result) {
return [$favorablePrice * $proportion['user_proportion']];
} else {
return [0];
}
}
/**
* 工作人员
* * @param int $id
* * @param string $amount
*/
function follow(int $id, string $amount)
{
$user_info = Db::name('release_user')->find($id);
$number = Db::name('release_follow')->where('user_id', $user_info['superior_id'])->count('id');
$money = floor($amount * 0.05);
if ($number < 2) {
if ($number == 1) {
$follow_money = Db::name('release_follow')->where('user_id', $user_info['superior_id'])->value('amount');
$follow_a = 100 - $follow_money;
if ($money < $follow_a) {
$superior_info = Db::name('release_user')->find($user_info['superior_id']);
Db::name('release_user')->where('id', $superior_info['id'])->update([
'balance' => $superior_info['balance'] + 100
]);
Db::name('release_detailed')->insert([
'user_id' => $user_info['superior_id'],
'detailed' => '订单佣金',
'transaction_number' => date('YmdHis', time()) . rand(111111, 999999),
'transaction_amount' => '+' . 100,
'withdrawa_status' => 2,
'remaining_balance' => $superior_info['balance'] + 100,
'create_time' => date('Y-m-d H:i:s', time())
]);
Db::name('release_follow')->insert([
'user_id' => $superior_info['id'],
'amount' => $money,
'create_time' => date('Y-m-d H:i:s', time())
]);
} elseif ($money > $follow_a) {
$superior_info = Db::name('release_user')->find($user_info['superior_id']);
Db::name('release_user')->where('id', $superior_info['id'])->update([
'balance' => $superior_info['balance'] + $money + $follow_money
]);
$a = $money + $follow_money;
Db::name('release_detailed')->insert([
'user_id' => $superior_info['id'],
'detailed' => '订单佣金',
'transaction_number' => date('YmdHis', time()) . rand(111111, 999999),
'transaction_amount' => '+' . $a,
'withdrawa_status' => 2,
'remaining_balance' => $superior_info['balance'] + 100,
'create_time' => date('Y-m-d H:i:s', time())
]);
Db::name('release_follow')->insert([
'user_id' => $superior_info['id'],
'amount' => $money,
'create_time' => date('Y-m-d H:i:s', time())
]);
}
} elseif ($number == 0) {
$superior_info = Db::name('release_user')->find($user_info['superior_id']);
Db::name('release_follow')->insert([
'user_id' => $superior_info['id'],
'amount' => $money,
'create_time' => date('Y-m-d H:i:s', time())
]);
// Db::name('release_detailed')->insert([
// 'user_id' => $id,
// 'detailed' => '订单佣金',
// 'transaction_number' => date('YmdHis', time()) . rand(111111, 999999),
// 'transaction_amount' => '+' . $money,
// 'withdrawa_status' => 2,
// 'remaining_balance' => $user_info['balance'] + 100,
// 'create_time' => date('Y-m-d H:i:s', time())
// ]);
}
}
}
/**
* 推荐人佣金
* * @param int $id
* * @param int $orderId
* * @param int $favorablePrice
*/
function RecommenderCommission(int $id, int $orderId, int $favorablePrice)
{
$proportion = Db::name('release_proportion')->find(1);
$userInfo = Db::name('release_user')->find($id);
$orderInfo = Db::name('release_order')->find($orderId);
$time = time() - strtotime($userInfo['create_time']);
if ($time / 86400 < 120) {
// return $favorablePrice * $proportion['superior_proportion'];
// dump($favorablePrice * $proportion['superior_proportion']);
// dump(judge($orderId, $favorablePrice));
// return $favorablePrice * $proportion['superior_proportion'];
return [$favorablePrice * $proportion['superior_proportion']];
} else {
return [0];
}
}
/**
* 判断时间
* * @param string $time
*/
function judgmentTime(string $time)
{
$time = strtotime($time) + 3600 * 8;
$overtime = time();
if ($overtime < $time) {
return true;
} else {
return false;
}
}
/**
* 判断两个任务单
* * @param int $orderId
* * @param int $favorablePrice
*/
function judge(int $orderId, int $favorablePrice)
{
$proportion = Db::name('release_proportion')->find(1);
$order = Db::name('release_order')->find($orderId);
$user = Db::name('release_user')->find($order['user_id']);
$subordinate = Db::name('release_user')->find($user['superior_id']);
$orderNumber = Db::name('release_order')->where('user_id', $order['user_id'])->find($orderId);
if ($orderNumber >= 2) {
return [0];
} else {
$number = Db::name('release_detailed')->where([
'user_id' => $subordinate['id'],
'subordinate_id' => $user['id']
])->count();
if ($number == 1) {
$info = Db::name('release_detailed')->where([
'user_id' => $subordinate['id'],
'subordinate_id' => $user['id']
])->find();
if ($favorablePrice * $proportion['two_task_orders'] > 100 - $info['transaction_amount']) {
return [$favorablePrice * $proportion['two_task_orders']];
} else {
return [100 - $info['transaction_amount']];
}
} else {
return [$favorablePrice * $proportion['two_task_orders']];
}
}
}
/**
* 返回获取的积分和经验值
* * @param int $Id
*/
function getInfo(int $Id)
{
$superior_user = Db::name('release_user')->where('id', $Id)->find();
$release_member = Db::name('release_member')->where('grade', $superior_user['grade'])->find();
if ($superior_user['grade'] != 'lv0') {
if ($superior_user['grade'] == 'lv1') {
$Grade = Grade($superior_user['experience'] + $release_member['basic_experience']);
Db::name('release_user')->where('id', $Id)->update([
'integral' => $superior_user['integral'] + $release_member['basic_integral'],
'experience' => $superior_user['experience'] + $release_member['basic_experience'],
'grade' => $Grade
]);
Db::name('release_exchange_details')->insert([
'user_id' => $Id,
'detailed' => '推广增加',
'integral' => '+' . $release_member['basic_integral'],
'create_time' => date('Y-m-d H:i:s', time())
]);
} else {
$release_member = Db::name('release_member')->where('grade', $superior_user['grade'])->find();
// $empirical_ratio = Db::name('release_member')->where('grade', $superior_user['grade'])->value('empirical_ratio');
// $integral = Db::name('release_system')->where('id', 3)->value('data');
// $empirical = Db::name('release_system')->where('id', 4)->value('data');
$Grade = Grade($superior_user['experience'] + $release_member['basic_experience'] * $release_member['empirical_ratio']);
Db::name('release_user')->where('id', $Id)->update([
'integral' => $superior_user['integral'] + $release_member['basic_integral'] * $release_member['integral_magnification'],
'experience' => $superior_user['experience'] + $release_member['basic_experience'] * $release_member['empirical_ratio'],
'grade' => $Grade
]);
Db::name('release_exchange_details')->insert([
'user_id' => $Id,
'detailed' => '推广增加',
'integral' => '+' . $release_member['basic_integral'] * $release_member['integral_magnification'],
'create_time' => date('Y-m-d H:i:s', time())
]);
}
}
}