作者 开飞机的舒克

条形码生成优化

... ... @@ -336,9 +336,9 @@ class Study extends Backend
}
$result = $this->model->allowField(true)->save($params);
$id = $this->model->id;
$sno = $this->model->sno;
$barpath = Resource::StudyBar($sno);
$this->model->save(['barcode'=>$barpath,'unique'=>$sno],['id'=>$id]);
$res = str_pad($id,8,"0",STR_PAD_LEFT);
$barpath = Resource::StudyBar($res);
$this->model->save(['barcode'=>$barpath,'unique'=>$res],['id'=>$id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ...
... ... @@ -5,7 +5,7 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\common\controller\Resource;
use tinymeng\code\Generate;
mb_internal_encoding("UTF-8");
/**
* 示例接口
*/
... ... @@ -69,16 +69,9 @@ class Demo extends Api
*/
public function test3()
{
$id = '三年级三班';
$arr = substr($id,0,1);
$map = array('一' => '1','二' => '2','三' => '3','四' => '4','五' => '5','六' => '6');
foreach ($map as $k => $v){
$k = $arr;
return $k;
}
// $res = str_pad($id,8,"0",STR_PAD_LEFT);
// dump($res);
dump($res);
}
}
... ...
... ... @@ -6,9 +6,9 @@ use tinymeng\code\Generate;
class Resource
{
public static function StudyBar($sno){
public static function StudyBar($res){
$generate = Generate::bar();
$file_path = $generate->create($sno,true,true);
$file_path = $generate->create($res,true,true);
$file_path = substr($file_path,strripos($file_path,"public")+6);
return $file_path;
}
... ...