first commit
This commit is contained in:
85
金壶/ydyd_service/application/common/tools/ContractMake.php
Normal file
85
金壶/ydyd_service/application/common/tools/ContractMake.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Env;
|
||||
use think\facade\Log;
|
||||
|
||||
class ContractMake
|
||||
{
|
||||
public function createPdf($order_info){
|
||||
//取得订单和采购商详情
|
||||
$buyer_info=Db::name('buyer')->field('name,organization_code')->where(['buyer_user_id'=>$order_info['user_id']])->find();
|
||||
|
||||
//取得平台信息详情
|
||||
$plat_info=Config::get('SYSTEM_CONSTANT')['CONTRACT_PLAT_INFO'];
|
||||
|
||||
//取得合同内容
|
||||
$contract_contents=Db::name('articles')->field('contents')->where(array('nid'=>'buy_contract'))->find();
|
||||
$contract_true_content=html_entity_decode($contract_contents['contents']);
|
||||
//替换部分内容
|
||||
$target_array=array('[total_amount]','[goods_amount]','[shipping_fee]');
|
||||
/*Log::info($order_info['total_amount'].' '.$order_info['goods_amount'].' '.$order_info['shipping_fee']);
|
||||
Log::info('总金额'.toChineseNumber('0.00'));
|
||||
Log::info('总金额'.toChineseNumber($order_info['total_amount']));
|
||||
Log::info('商品金额'.toChineseNumber($order_info['goods_amount']));
|
||||
Log::info('物流金额'.toChineseNumber($order_info['shipping_fee']));*/
|
||||
$replace_array=array(toChineseNumber($order_info['total_amount']).'('.$order_info['total_amount'].'元)',toChineseNumber($order_info['goods_amount']).'('.$order_info['goods_amount'].'元)',toChineseNumber($order_info['shipping_fee']).'('.$order_info['shipping_fee'].'元)');
|
||||
$contract_true_content=str_replace($target_array,$replace_array,$contract_true_content);
|
||||
$order_info['contract_contents']=$contract_true_content;
|
||||
|
||||
//取得附件产品信息详情内容
|
||||
$_where[] = ['og.order_id','=',$order_info['order_id']];
|
||||
$_where[] = ['og.is_delete','=',0];
|
||||
$order_goods = Db::name("order_goods")->alias("og")->leftJoin('goods g','g.goods_id = og.goods_id')
|
||||
->leftJoin('manufacturer m','m.id = g.manufacturer_id')
|
||||
->where($_where)->field("og.type,og.unit_price,og.spread_unit_price,og.spread_flag,og.goods_number,og.name as extend_name,og.spec_desc as extend_spec_desc,og.manufacturer_name as extend_m_name,g.name,g.spec_desc,m.name as m_name")->select();
|
||||
$goods_list = [];
|
||||
foreach ($order_goods as $item){
|
||||
$tmp_info=[];
|
||||
if ($item['type'] == 'extend'){
|
||||
$tmp_info[] = $item['extend_name'];
|
||||
$tmp_info[] = $item['extend_spec_desc'];
|
||||
$tmp_info[] = $item['extend_m_name'];
|
||||
} else {
|
||||
$tmp_info[] = $item['name'];
|
||||
$tmp_info[] = $item['spec_desc'];
|
||||
$tmp_info[] = $item['m_name'];
|
||||
}
|
||||
|
||||
if ($item['spread_flag']==1) {
|
||||
$unit_price = $item['spread_unit_price'];
|
||||
} else {
|
||||
$unit_price = $item['unit_price'];
|
||||
}
|
||||
$tmp_info[] = $unit_price;
|
||||
$tmp_info[] = $item['goods_number'];
|
||||
$tmp_info[] = number_format($unit_price*$item['goods_number'],2,'.','');
|
||||
$goods_list[] = $tmp_info;
|
||||
}
|
||||
|
||||
$order_info['goods_info']=$goods_list;
|
||||
|
||||
$pdffile=array();
|
||||
$fileName = $order_info['order_sn'].'-'.mt_rand(0,100000).'-'.time();
|
||||
$pdffile['name']=Env::get('app_path').'ContractFile/'.$fileName.'.pdf';
|
||||
$target_filename='ContractFile/'.$fileName.'.pdf';
|
||||
$pdffile['password']='';
|
||||
$pdffile['type']='F';
|
||||
|
||||
try {
|
||||
model('CreatePdf','service')->createContractPdf($pdffile,$plat_info,$buyer_info,$order_info);
|
||||
$res_return = model('OssUpload', 'service')->UploadFileToOss($pdffile['name'],$target_filename);
|
||||
return $res_return;
|
||||
} catch (Exception $e) {
|
||||
Log::info($e->getTraceAsString());
|
||||
$res_return['errcode'] = -1;
|
||||
$res_return['errmsg'] = "生成订单合同失败";
|
||||
return $res_return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user