123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- <?php
- use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
- use AlibabaCloud\Tea\Exception\TeaError;
- use AlibabaCloud\Tea\Utils\Utils;
- use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
- use app\data\model\DataUserRepair;
- use app\data\model\ShopPurchase;
- use Darabonba\OpenApi\Models\Config;
- use think\admin\model\SystemConfig;
- use app\common\library\QRcode;
- use PhpOffice\PhpWord\TemplateProcessor;
- function systemConfig($name,$value=null){
- $nameArr=array_filter(explode('.',$name));
- if(is_null($value)){
- if(count($nameArr)==1) {
- $source = SystemConfig::where('type', $nameArr[0])->select();
- $data=[];
- foreach ($source as $model){
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- $data[$model['name']]=$value;
- }
- return $data?:null;
- }else{
- $model = SystemConfig::where('type', $nameArr[0])->where('name',$nameArr[1])->find();
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- return $value;
- }
- }else{
- SystemConfig::where('type', $nameArr[0])->delete();
- if(count($nameArr)==1) {
- if(is_array($value)){
- foreach ($value as $key=>$val){
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$key,
- 'value'=>is_array($val)?json_encode($val,256):$val,
- ]);
- }
- }
- }else{
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$nameArr[1],
- 'value'=>$value,
- ]);
- }
- }
- }
- /**
- * 生成??位随机数
- */
- function get32Str($length='32'){
- // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
- /**
- * 使用AK&SK初始化账号Client
- * @param string $accessKeyId
- * @param string $accessKeySecret
- * @return Cloudauth Client
- */
- function createClient($accessKeyId, $accessKeySecret){
- $config = new Config([
- // 您的 AccessKey ID
- "accessKeyId" => $accessKeyId,
- // 您的 AccessKey Secret
- "accessKeySecret" => $accessKeySecret,
- ]);
- // 访问的域名
- $config->endpoint = "cloudauth.aliyuncs.com";
- return new Cloudauth($config);
- }
- /**
- * @param string[] $args
- * @return void
- */
- function main($certName,$certNo,$metaInfo,$ReturnUrl){
- $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
- $initFaceVerifyRequest = new InitFaceVerifyRequest([
- "sceneId" => '1000006090',
- "outerOrderNo" => get32Str(),
- // 要接入的认证方案。
- "productCode" => "ID_PRO",
- "certType" => "IDENTITY_CARD",
- "certName" => $certName,
- "certNo" => $certNo,
- // MetaInfo环境参数,需要通过客户端SDK获取。
- "metaInfo" => $metaInfo,
- "returnUrl" => $ReturnUrl,
- ]);
- $runtime = new RuntimeOptions([]);
- try {
- // 复制代码运行请自行打印 API 的返回值
- $res = $client->initFaceVerifyWithOptions($initFaceVerifyRequest, $runtime);
- return $res;
- } catch (Exception $error) {
- if (!($error instanceof TeaError)) {
- $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
- }
- // 如有需要,请打印 error
- Utils::assertAsString($error->message);
- return '';
- }
- }
- /**
- * @param string[] $args
- * @return void
- */
- function check($CertifyId){
- $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
- $describeFaceVerifyRequest = new DescribeFaceVerifyRequest([
- 'sceneId' => '1000006090',
- 'certifyId' => $CertifyId,
- ]);
- $runtime = new RuntimeOptions([]);
- try {
- // 复制代码运行请自行打印 API 的返回值
- $rs = $client->describeFaceVerifyWithOptions($describeFaceVerifyRequest, $runtime);
- return $rs;
- }
- catch (Exception $error) {
- if (!($error instanceof TeaError)) {
- $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
- }
- // 如有需要,请打印 error
- Utils::assertAsString($error->message);
- return false;
- }
- }
- /**
- * 生成二维码
- */
- function setqrcode($value,$name){
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/';
- if(!file_exists($dir)){
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($dir, 0700,true);
- }
- $filename = $dir.'/'.$name.'.png';
- QRcode::png($value,$filename,QR_ECLEVEL_L,7);
- $url = 'http://'.$_SERVER['SERVER_NAME']."/".$name.'.png';
- return $url;
- }
- //生成邀请二维码
- function setappcode($address){
- $name = time();
- $url = setqrcode($address,$name);
- return $url;
- }
- //维修单,四大订单生成下载文件
- function setword($type,$id){
- $url = '';
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/';
- $dir2 = $dir.'down/';
- if(!file_exists($dir2)){
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($dir2, 0700,true);
- }
- switch ($type){
- case 1: //维修订单
- $templateProcessor = new TemplateProcessor($dir.'/wxdd.docx');
- $info = DataUserRepair::mk()->with(['user','user2'])->findOrEmpty($id);
- $array = [
- 'order_no'=>$info['order_no'],
- 'date'=>$info['start_time'],
- 'fbz'=>$info['user']['nickname'],
- 'jdf'=>$info['user2']['nickname'],
- 'fbzphone'=>$info['user']['phone'],
- 'jdfphone'=>$info['user2']['phone'],
- 'address'=>$info['province'].$info['city'].$info['area'].$info['address'],
- 'time'=>$info['start_time'].'-'.$info['end_time'],
- 'desc'=>$info['describe'],
- 'price'=>$info['success_price']
- ];
- $templateProcessor->setValues($array);
- $name = 'wxdd-'.$id.'-'.time().'.docx';
- $url = 'http://'.$_SERVER['SERVER_NAME']."/down/".$name;
- $templateProcessor->saveAs($dir2.$name);
- break;
- case 2: //采购订单
- $templateProcessor = new TemplateProcessor($dir.'/cgdd.docx');
- $info = $model=ShopPurchase::getItem(1)
- ->lock(true)
- ->where('purchase_id',$id)
- ->with(['main','ppoffer','main.merchant','ppoffer.user'])
- ->findOrEmpty();
- // dump($info->toArray());die;
- $allprice = bcmul($info['price'],$info['number'],2);
- $array = [
- 'order_no'=>$info['main']['order_no'],
- 'date'=>date('Y-m-d',strtotime($info['main']['post_time'])),
- 'shopname'=>$info['main']['merchant']['name'],
- 'mfname'=>$info['main']['merchant']['contact_name'],
- 'mfphone'=>$info['main']['merchant']['contact_phone'],
- 'mmfname'=>$info['ppoffer']['user']['nickname'],
- 'mmfphone'=>$info['ppoffer']['user']['phone'],
- 'id'=>1,
- 'name'=>$info['name'],
- 'gg'=>$info['spec'],
- 'num'=>$info['number'],
- 'price'=>$info['price'],
- 'allprice'=>$allprice,
- 'dxprice'=>num_to_rmb($allprice),
- 'toprice'=>$allprice,
- 'sprice'=>$info['ppoffer']['amount']
- ];
- $templateProcessor->setValues($array);
- $name = 'cgdd-'.$id.'-'.time().'.docx';
- $url = 'http://'.$_SERVER['SERVER_NAME']."/down/".$name;
- $templateProcessor->saveAs($dir2.$name);
- break;
- case 3: //生产订单
- $templateProcessor = new TemplateProcessor($dir.'/scdd.docx');
- $info =ShopPurchase::getItem(2)
- ->with(['merchant','items','ppoffer','ppoffer.user'])
- ->lock(true)
- ->findOrEmpty($id);
- dump($info->toArray());
- echo count($info['items']);die;
- die;
- $array = [
- 'order_no'=>$info['order_no'],
- 'date'=>date('Y-m-d',strtotime($info['post_time'])),
- 'shopname'=>$info['merchant']['name'],
- 'mfname'=>$info['merchant']['contact_name'],
- 'mfphone'=>$info['merchant']['contact_phone'],
- 'mmfname'=>$info['ppoffer']['user']['nickname'],
- 'mmfphone'=>$info['ppoffer']['user']['phone'],
- 'id'=>1,
- 'name'=>$info['name'],
- 'gg'=>$info['spec'],
- 'num'=>$info['number'],
- 'price'=>$info['price'],
- 'allprice'=>$allprice,
- 'dxprice'=>num_to_rmb($allprice),
- 'toprice'=>$allprice,
- 'sprice'=>$info['ppoffer']['amount']
- ];
- break;
- case 4: //外协订单
- break;
- case 5: //海运订单
- break;
- }
- return $url;
- }
- /**
- *数字金额转换成中文大写金额的函数
- *String Int $num 要转换的小写数字或小写字符串
- *return 大写字母
- *小数位为两位
- **/
- function num_to_rmb($num){
- $c1 = "零壹贰叁肆伍陆柒捌玖";
- $c2 = "分角元拾佰仟万拾佰仟亿";
- //精确到分后面就不要了,所以只留两个小数位
- $num = round($num, 2);
- //将数字转化为整数
- $num = $num * 100;
- if (strlen($num) > 10) {
- return "金额太大,请检查";
- }
- $i = 0;
- $c = "";
- while (1) {
- if ($i == 0) {
- //获取最后一位数字
- $n = substr($num, strlen($num)-1, 1);
- } else {
- $n = $num % 10;
- }
- //每次将最后一位数字转化为中文
- $p1 = substr($c1, 3 * $n, 3);
- $p2 = substr($c2, 3 * $i, 3);
- if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
- $c = $p1 . $p2 . $c;
- } else {
- $c = $p1 . $c;
- }
- $i = $i + 1;
- //去掉数字最后一位了
- $num = $num / 10;
- $num = (int)$num;
- //结束循环
- if ($num == 0) {
- break;
- }
- }
- $j = 0;
- $slen = strlen($c);
- while ($j < $slen) {
- //utf8一个汉字相当3个字符
- $m = substr($c, $j, 6);
- //处理数字中很多0的情况,每次循环去掉一个汉字“零”
- if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
- $left = substr($c, 0, $j);
- $right = substr($c, $j + 3);
- $c = $left . $right;
- $j = $j-3;
- $slen = $slen-3;
- }
- $j = $j + 3;
- }
- //这个是为了去掉类似23.0中最后一个“零”字
- if (substr($c, strlen($c)-3, 3) == '零') {
- $c = substr($c, 0, strlen($c)-3);
- }
- //将处理的汉字加上“整”
- if (empty($c)) {
- return "零元整";
- }else{
- return $c . "整";
- }
- }
|