发票管理apiadmin
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.
 
 
 

117 lines
2.8 KiB

<?php
namespace app\service\user;
use app\model\InvoiceHead;
use app\model\WechatPucode;
use app\model\WechatUser;
use app\service\BaseService;
class UserService extends BaseService
{
/**
* 随机字符串,默认长度10
* @param int $num
* @return string
*/
public function setSalt(int $num = 10): string
{
$str = 'qwertyuiopasdfghjklzxcvbnm1234567890';
return substr(str_shuffle($str), 10, $num);
}
/**
* 密码加密
* @param string $pwd
* @param string $salt
* @return string
*/
public function setPassword(string $pwd, string $salt): string
{
return md5(md5($pwd . $salt) . $salt);
}
/**
* 添加、修改密码
* @param $id
* @param $password
* @return bool
*/
public function savePassword($id, $password)
{
$salt = $this->setSalt();
$savePassword = $this->setPassword($password, $salt);
$data = [
'password' => $savePassword,
'salt' => $salt
];
$User = new WechatUser();
return $User->where('id', $id)->save($data);
}
public static function addUser(
int $phone,
string $email,
string $pucode,
string $tax_number,
int $type
)
{
$query = WechatUser::where('phone', $phone)->find();
if (!$query) {
$save = [
'nickname' => '导入用户',
'phone' => $phone,
'email' => $email
];
$id = (new WechatUser())->insertGetId($save);
if ($id) {
$codeSave = [
'wechat_user_id' => $id,
'pucode' => $pucode,
'create_time' => time()
];
(new WechatPucode())->save($codeSave);
if ($codeSave) {
$headSave = [
'tax_number' => $tax_number,
];
$headQuery = InvoiceHead::where($headSave)->find();
if (!$headQuery) {
$headSave['type'] = $type;
$headSave['phone'] = $phone;
$headSave['wechat_user_id'] = $id;
$headSave['create_time'] = time();
(new InvoiceHead())->save($headSave);
}
}
}
return 1;
}
return 0;
}
public static function getTaxUser($tax_id)
{
$where = [
'tax_number' => $tax_id
];
$user_ids = InvoiceHead::where($where)->column('wechat_user_id');
if ($user_ids) {
return WechatPucode::whereIn('wechat_user_id', $user_ids)->column('pucode');
}
}
}