OrderContractSvc.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\Orders;
  4. use think\View;
  5. class OrderContractSvc{
  6. /** @var Orders */
  7. protected $order;
  8. /**
  9. * @param Orders $order
  10. */
  11. public static function setOrder(Orders $order)
  12. {
  13. $new=new self;
  14. $new->order = $order;
  15. return $new;
  16. }
  17. /**
  18. * @return Orders
  19. */
  20. public function getOrder(): Orders
  21. {
  22. return $this->order;
  23. }
  24. public function render(){
  25. $content=redis()->hGet('order_contract',$this->getOrder()->id)?:'';
  26. if(!$content){
  27. try {
  28. $content=View::instance()
  29. ->config('view_path',APP_PATH.'contract/view/')
  30. ->fetch('show',[
  31. 'order'=>$this->getOrder(),
  32. 'no'=>sprintf('PK%s%02d',date('YmdHis'),$this->getOrder()->id),
  33. 'tax_name'=>$this->taxName(),
  34. 'tax_no'=>$this->getTaxNo(),
  35. ]);
  36. }catch (\Exception $e){
  37. $content='';
  38. }
  39. redis()->hSet('order_contract',$this->getOrder()->id,$content);
  40. }
  41. return $content;
  42. }
  43. public function taxName(){
  44. $tax=$this->getOrder()->tax;
  45. if(empty($tax)){
  46. return '';
  47. }
  48. if($tax['u_type']==1){
  49. return $tax['name'];
  50. }
  51. return $tax['open_name'];
  52. }
  53. public function getTaxNo(){
  54. return $this->getOrder()->tax['tax_no']??'';
  55. }
  56. }