1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\common\service;
- use app\common\model\Orders;
- use think\View;
- class OrderContractSvc{
- /** @var Orders */
- protected $order;
- /**
- * @param Orders $order
- */
- public static function setOrder(Orders $order)
- {
- $new=new self;
- $new->order = $order;
- return $new;
- }
- /**
- * @return Orders
- */
- public function getOrder(): Orders
- {
- return $this->order;
- }
- public function render(){
- $content=redis()->hGet('order_contract',$this->getOrder()->id)?:'';
- if(!$content){
- try {
- $content=View::instance()
- ->config('view_path',APP_PATH.'contract/view/')
- ->fetch('show',[
- 'order'=>$this->getOrder(),
- 'no'=>sprintf('PK%s%02d',date('YmdHis'),$this->getOrder()->id),
- 'tax_name'=>$this->taxName(),
- 'tax_no'=>$this->getTaxNo(),
- ]);
- }catch (\Exception $e){
- $content='';
- }
- redis()->hSet('order_contract',$this->getOrder()->id,$content);
- }
- return $content;
- }
- public function taxName(){
- $tax=$this->getOrder()->tax;
- if(empty($tax)){
- return '';
- }
- if($tax['u_type']==1){
- return $tax['name'];
- }
- return $tax['open_name'];
- }
- public function getTaxNo(){
- return $this->getOrder()->tax['tax_no']??'';
- }
- }
|