| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace frontendApi\modules\v1\controllers;
- use Codeception\PHPUnit\ResultPrinter\HTML;
- use common\helpers\Date;
- use common\helpers\Form;
- use common\helpers\user\Info;
- use common\models\DealType;
- use common\models\DecOrder;
- use common\models\forms\DeclarationForm;
- use common\models\forms\OrderForm;
- use common\models\Order;
- use common\models\OrderDec;
- use common\models\OrderGoods;
- use common\models\OrderGoodsDec;
- use common\models\ReceiveAddress;
- use common\models\Region;
- use common\models\ShopGoods;
- use common\models\User;
- use common\models\UserBonus;
- use common\models\UserWallet;
- use Yii;
- class ShopController extends BaseController {
- public $modelClass = DecOrder::class;
- /**
- * 商品列表
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionIndex() {
- // 商品分类
- $categoryType = \Yii::$app->request->get('categoryType', 1);
- $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0';
- $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
- if($isStudio==1){
- $condition.= " OR FIND_IN_SET(4,GIFT_TYPE)>0";
- }
- $condition .= ") AND CATEGORY_TYPE = :CATEGORY_TYPE";
- $params[':CATEGORY_TYPE'] = intval($categoryType);
- $data = ShopGoods::lists($condition, $params, [
- 'orderBy' => 'SORT ASC,CREATED_AT DESC',
- 'from' => ShopGoods::tableName(),
- ]);
- foreach ($data['list'] as $key => $value) {
- if ($value['TYPE'] == 1 || $value['TYPE'] == 2) {
- $data['list'][$key]['DISCOUNT'] = ShopGoods::GOODS_TYPE[$value['TYPE']]['discount'];
- } else {
- $data['list'][$key]['DISCOUNT'] = $value['SELL_DISCOUNT']*100;
- }
- // $data['list'][$key]['DISCOUNT'] = ShopGoods::GOODS_TYPE[$value['TYPE']]['discount'];
- }
- return static::notice($data);
- }
- /**
- * 获取商品详情
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionGoodsDetail(){
- $id = \Yii::$app->request->get('id');
- $data = null;
- if($id){
- $data = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1', [':ID'=>$id]);
- }
- return static::notice($data);
- }
- /**
- * 购物车订单展示
- * @throws \yii\web\HttpException
- */
- public function actionShowCart(){
- $userId = \Yii::$app->user->id;
- $payList = ShopGoods::payTypes();
- $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
- if($allAddress) {
- foreach ($allAddress as $key => $row) {
- $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
- $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
- $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
- }
- }
- $userBalance = [
- 'points' => 0,
- 'cash' => 0,
- 'exchange' => 0,
- 'travel_points' => 0,
- 'car_points' => 0,
- 'house_points' => 0,
- ];
- if ($userBonusResult = UserBonus::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['points'] = $userBonusResult['RECONSUME_POINTS'];
- $userBalance['exchange'] = $userBonusResult['EXCHANGE_POINTS'];
- $userBalance['travel_points'] = $userBonusResult['TRAVEL_POINTS'];
- $userBalance['car_points'] = $userBonusResult['CAR_POINTS'];
- $userBalance['house_points'] = $userBonusResult['HOUSE_POINTS'];
- }
- if ($userCashResult = UserWallet::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['cash'] = $userCashResult['CASH'];
- }
- return static::notice(
- [
- 'payList'=>$payList,
- 'allAddress'=>$allAddress,
- 'userBalance'=>$userBalance,
- 'sellType' => ShopGoods::CATEGORY_TYPE,
- ]);
- }
- /**
- * 确认订单
- */
- public function actionSureOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderForm();
- $formModel->scenario = 'userOrder';
- $formModel->remark = '复销备注';
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- if ($formModel->load($post, '') && $order = $formModel->add()) {
- return static::notice($order);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * 订单支付成功
- * @throws \yii\web\HttpException
- */
- public function actionPaySuccess(){
- $orderSn = \Yii::$app->request->get('orderSn');
- $data = null;
- if($orderSn){
- $data = Order::findOneAsArray('SN=:SN', [':SN'=>$orderSn]);
- }
- return static::notice($data);
- }
- /**
- * 订单支付成功
- * @throws \yii\web\HttpException
- */
- public function actionVerifyOrder(){
- if (\Yii::$app->request->isPost) {
- return parent::edit(OrderForm::class, 'PayStack pay Success', 'verifyPayStack', ['verifyPayStack']);
- }
- return static::notice('非法请求', 400);
- }
- /**
- * 我的报单
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionDecOrderList() {
- $condition = ' AND USER_ID=:USER_ID AND IS_DEL=0';
- $params[':USER_ID'] = \Yii::$app->user->id;
- $data = DecOrder::lists($condition, $params, [
- 'select' => 'DO.*,U.USER_NAME USER_NAME,U.REAL_NAME REAL_NAME,RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,OG.*',
- 'orderBy' => 'DO.CREATED_AT DESC',
- 'from' => DecOrder::tableName() . ' AS DO',
- 'join' => [
- ['LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID'],
- ['LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID'],
- ['LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID'],
- ['LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN'],
- ],
- ]);
- return static::notice($data);
- }
- /**
- * 我的订单
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionOrderList() {
- $uname = Info::getUserNameByUserId(\Yii::$app->user->id);
- $condition = " AND ORDER_TYPE='FX' AND (USER_ID=:USER_ID OR CREATE_USER='$uname')";
- $params[':USER_ID'] = \Yii::$app->user->id;
- $data = Order::lists($condition, $params, [
- 'select' => 'O.*,U.REAL_NAME,OG.*,SG.CATEGORY_TYPE',
- 'orderBy' => 'O.CREATED_AT DESC',
- 'from' => Order::tableName() . ' AS O',
- 'join' => [
- ['LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID'],
- ['LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN'],
- ['LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID'],
- ],
- ]);
- foreach ($data['list'] as $key => $value) {
- $data['list'][$key]['PAY_AT'] = $value['PAY_AT'] ? Date::convert($value['PAY_AT'],'Y-m-d H:i:s') : '';
- $data['list'][$key]['CATEGORY_TYPE'] = intval($value['CATEGORY_TYPE']);
- $data['list'][$key]['PAY_TYPE'] = array_column(ShopGoods::SALE_TYPE, NULL, 'label')[$value['PAY_TYPE']]['name'] ?? '';
- $data['list'][$key]['STATUS'] = \Yii::$app->params['orderStatus'][$value['STATUS']]['label'] ?? '';
- $data['list'][$key]['CATEGORY'] = array_column(ShopGoods::CATEGORY_TYPE, NULL, 'id')[$value['CATEGORY_TYPE']]['name'] ?? '普通商品';
- $data['list'][$key]['FULL_ADDRESS'] = '';
- if($value['PROVINCE']){
- $data['list'][$key]['FULL_ADDRESS'] .= Region::getCnName($value['PROVINCE']);
- }
- if($value['CITY']){
- $data['list'][$key]['FULL_ADDRESS'] .= Region::getCnName($value['CITY']);
- }
- if($value['COUNTY']){
- $data['list'][$key]['FULL_ADDRESS'] .= Region::getCnName($value['COUNTY']);
- }
- $data['list'][$key]['FULL_ADDRESS'] .= $value['ADDRESS'];
- }
- return static::notice($data);
- }
- /**
- * 会员复消
- */
- public function actionReconsume() {
- $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0 OR FIND_IN_SET(4,GIFT_TYPE)>0)';
- $data = ShopGoods::lists($condition, [], [
- 'orderBy' => 'SORT ASC,CREATED_AT DESC',
- 'from' => ShopGoods::tableName(),
- ]);
- foreach ($data['list'] as $key => $value) {
- if ($value['TYPE'] == 1 || $value['TYPE'] == 2) {
- $data['list'][$key]['DISCOUNT'] = ShopGoods::GOODS_TYPE[$value['TYPE']]['discount'];
- } else {
- $data['list'][$key]['DISCOUNT'] = $value['SELL_DISCOUNT']*100;
- }
- //$data['list'][$key]['DISCOUNT'] = ShopGoods::GOODS_TYPE[$value['TYPE']]['discount'];
- }
- return static::notice($data);
- }
- /**
- * 帮会员复消购物车
- * @throws \yii\web\HttpException
- */
- public function actionReconsumeCart(){
- $userId = \Yii::$app->user->id;
- $payList = ['cash'=>['name'=>'Balance payment'],];//余额支付
- $userBalance = [
- 'points' => 0,
- 'cash' => 0
- ];
- if ($userBonusResult = UserBonus::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['points'] = $userBonusResult['RECONSUME_POINTS'];
- }
- if ($userCashResult = UserWallet::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['cash'] = $userCashResult['CASH'];
- }
- return static::notice(['payList'=>$payList,'userBalance'=>$userBalance]);
- }
- /**
- * 帮会员复消确认订单
- */
- public function actionReconsumeSureOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderForm();
- $formModel->scenario = 'reconsumeOrder';
- $formModel->remark = '帮会员复销';
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- if ($formModel->load($post, '') && $formModel->reconsumeAdd()) {
- return static::notice('帮会员复消成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * 商品列表tabs分类
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionGoodsActive()
- {
- $data = [
- // [
- // 'name' => 'bonus',
- // 'label' => '奖金商品',
- // ],
- [
- 'name' => '1',
- 'label' => 'Standard Products',//普通商品列表
- ],
- [
- 'name' => '4',
- 'label' => 'Travel Bonus Products',//旅游积分商品
- ],
- [
- 'name' => '5',
- 'label' => 'Car Bonus Products',//名车积分商品
- ],
- [
- 'name' => '6',
- 'label' => 'House Bonus Products',//豪宅积分商品
- ],
- ];
- return static::notice($data);
- }
- /**
- * 导出订单.
- * @return mixed
- * @throws \yii\web\HttpException
- * @throws \Mpdf\MpdfException
- */
- public function actionOrderExport()
- {
- $uname = Info::getUserNameByUserId(\Yii::$app->user->id);
- $orderSn = \Yii::$app->request->get('orderSn');
- $condition = " AND ORDER_TYPE='FX' AND (USER_ID=:USER_ID OR CREATE_USER='$uname') AND SN=:SN";
- $params = [
- ':USER_ID' => \Yii::$app->user->id,
- ':SN' => $orderSn,
- ];
- $data = Order::lists($condition, $params, [
- 'select' => 'O.*,U.REAL_NAME,OG.*,OG.CATEGORY_TYPE',
- 'orderBy' => 'O.CREATED_AT DESC',
- 'from' => Order::tableName() . ' AS O',
- 'join' => [
- ['LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID'],
- ['LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN'],
- ],
- ]);
- $userId = '';
- $userName = '';
- $address = '';
- $mobile = '';
- $orderAt = '';
- $orderDetails = '';
- $orderAmount = 0; // 合计总额
- $orderNums = 0; // 合计总数
- foreach ($data['list'] as $key => $value) {
- $provinceName = $value['PROVINCE'] ? Region::getCnName($value['PROVINCE']) : '';
- $cityName = $value['CITY'] ? Region::getCnName($value['CITY']) : '';
- $countyName = $value['COUNTY'] ? Region::getCnName($value['COUNTY']) : '';
- $userId = $value['USER_NAME'];
- $userName = $value['REAL_NAME'];
- $address = $provinceName . $cityName . $countyName . $value['ADDRESS'];
- $mobile = $value['MOBILE'];
- $orderAt = Date::convert($value['PAY_AT'],'Y-m-d H:i:s');
- // 总价
- $totalAmount = $value['BUY_NUMS'] * $value['ORDER_AMOUNT'];
- $orderAmount += $totalAmount;
- $orderNums += $value['BUY_NUMS'];
- // 订单详情
- $orderDetails .= <<<EOT
- <tr>
- <td>{$value['SKU_CODE']}</td>
- <td>{$value['GOODS_TITLE']}</td>
- <td>{$value['BUY_NUMS']}</td>
- <td>{$value['ORDER_AMOUNT']}</td>
- <td>{$totalAmount}</td>
- </tr>
- EOT;
- }
- // 订单基本信息
- $orderBase = <<<ORDER
- <table border="1" style="table-layout: fixed; padding: 10px 20px;" width="100%">
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员编号</td>
- <td width="70%">{$userId}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员名字</td>
- <td width="70%">{$userName}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员地址</td>
- <td width="70%">{$address}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员电话</td>
- <td width="70%">{$mobile}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单编号</td>
- <td width="70%">{$orderSn}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单日期</td>
- <td width="70%">{$orderAt}</td>
- </tr>
- <tr>
- <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">订单明细</td>
- <td class="bg"></td>
- </tr>
- </table>
- ORDER;
- $l['a_meta_charset'] = 'UTF-8';
- $l['a_meta_dir'] = 'ltr';
- $l['a_meta_language'] = 'zh';
- $l['w_page'] = '页面';
- $context = <<<ORDER
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>订单详情</title>
- <style>
- table {
- border-collapse: collapse;
- }
- table td, table th {
- border: 1px solid #ccc;
- padding: 10px 30px;
- border-collapse: collapse;
- }
- td {
- padding: 120px;
- }
- .bg {
- background-color: #ccc;
- }
- </style>
- </head>
- <body>
- <div class="content">
- <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>订单详情</b><br></p>
- <div>
- <div style="display: block; width: 100%;">
- {$orderBase}
-
- <table border="1" width="100%" style="padding: 10px 20px; text-align: center;">
- <tr>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">商品编号</th>
- <th width="30%" style="font-size: 14px; font-weight: bold; text-align: center;">商品名称</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">数量</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">单价</th>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">总价</th>
- </tr>
- {$orderDetails}
- <tr>
- <td colspan="2">合计</td>
- <td>{$orderNums}</td>
- <td></td>
- <td>{$orderAmount}</td>
- </tr>
- </table>
- </div>
-
- <div style="width: 100%; margin-top: 50px; height: 30px;">
- <table width="100%" style="border: none; padding: 10px 20px; text-align: center;">
- <tr style="border: none;">
- <td width="70%" style="border: none;"></td>
- <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">签名:</td>
- </tr>
- <tr style="border: none;">
- <td width="70%" style="border: none;"></td>
- <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">日期:</td>
- </tr>
- </table>
- </div>
- </div>
- </div>
- </body>
- </html>
- ORDER;
- require_once (\Yii::$app->vendorPath . '/tecnickcom/tcpdf/tcpdf.php');
- $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
- // 设置打印模式
- $pdf->SetCreator(PDF_CREATOR);
- $pdf->SetAuthor('DaZe');
- $pdf->SetTitle($orderSn);
- $pdf->SetSubject('TCPDF Tutorial');
- $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
- // 是否显示页眉
- $pdf->setPrintHeader(false);
- // 设置页眉字体
- $pdf->setHeaderFont(Array('dejavusans', '', '12'));
- // 页眉距离顶部的距离
- $pdf->SetHeaderMargin('5');
- // 是否显示页脚
- $pdf->setPrintFooter(false);
- // 设置默认等宽字体
- $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
- // 设置行高
- $pdf->setCellHeightRatio(1);
- // 设置左、上、右的间距
- $pdf->SetMargins('10', '10', '10');
- // 设置是否自动分页 距离底部多少距离时分页
- $pdf->SetAutoPageBreak(TRUE, '15');
- // 设置图像比例因子
- $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
- if (@file_exists(\Yii::$app->vendorPath . 'tecnickcom/tcpdf/examples/lang/eng.php')) {
- require_once(\Yii::$app->vendorPath . '/tecnickcom/tcpdf/examples/lang/eng.php');
- $pdf->setLanguageArray($l);
- }
- $pdf->setFontSubsetting(true);
- $pdf->AddPage();
- // 设置字体
- $pdf->SetFont('stsongstdlight', '', 10, '', true);
- $pdf->writeHTML($context);
- ob_clean();
- $file_name = $orderSn . '.pdf';
- $path = 'pdfs/' . $file_name;
- $pdf->Output(Yii::$app->basePath . '/web/' . $path, 'F');
- @exec('chmod -R 777 /' . Yii::$app->basePath . '/web' . $path);
- return static::notice(['fileUrl' => $path, 'targetName' => $file_name]);
- }
- /**
- * 导出订单.
- * @return mixed
- * @throws \yii\web\HttpException
- * @throws \Mpdf\MpdfException
- */
- public function actionDecOrderExport()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $condition = ' AND DO.USER_ID=:USER_ID AND IS_DEL=0 AND DO.ORDER_SN=:ORDER_SN';
- $params = [
- ':USER_ID' => \Yii::$app->user->id,
- ':ORDER_SN' => $orderSn,
- ];
- $data = DecOrder::lists($condition, $params, [
- 'select' => 'DO.*,U.USER_NAME USER_NAME,U.REAL_NAME REAL_NAME,RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,OG.*,OD.PROVINCE,OD.CITY,OD.COUNTY,OD.ADDRESS,OD.MOBILE,OD.PAY_AT,OD.ORDER_AMOUNT',
- 'orderBy' => 'DO.CREATED_AT DESC',
- 'from' => DecOrder::tableName() . ' AS DO',
- 'join' => [
- ['LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID'],
- ['LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID'],
- ['LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID'],
- ['LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN'],
- ['LEFT JOIN', Order::tableName() . ' AS OD', 'OD.SN=DO.ORDER_SN'],
- ],
- ]);
- $userId = '';
- $userName = '';
- $address = '';
- $mobile = '';
- $orderAt = '';
- $orderDetails = '';
- $orderAmount = 0; // 合计总额
- $orderNums = 0; // 合计总数
- foreach ($data['list'] as $key => $value) {
- $provinceName = $value['PROVINCE'] ? Region::getCnName($value['PROVINCE']) : '';
- $cityName = $value['CITY'] ? Region::getCnName($value['CITY']) : '';
- $countyName = $value['COUNTY'] ? Region::getCnName($value['COUNTY']) : '';
- $userId = $value['USER_NAME'];
- $userName = $value['REAL_NAME'];
- $address = $provinceName . $cityName . $countyName . $value['ADDRESS'];
- $mobile = $value['MOBILE'];
- $orderAt = Date::convert($value['PAY_AT'],'Y-m-d H:i:s');
- // 总价
- $totalAmount = $value['BUY_NUMS'] * $value['REAL_PRICE'];
- $orderAmount += $totalAmount;
- $orderNums += $value['BUY_NUMS'];
- // 订单详情
- $orderDetails .= <<<EOT
- <tr>
- <td>{$value['SKU_CODE']}</td>
- <td>{$value['GOODS_TITLE']}</td>
- <td>{$value['BUY_NUMS']}</td>
- <td>{$value['REAL_PRICE']}</td>
- <td>{$totalAmount}</td>
- </tr>
- EOT;
- }
- // 订单基本信息
- $orderBase = <<<ORDER
- <table border="1" style="table-layout: fixed; padding: 10px 20px;" width="100%">
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员编号</td>
- <td width="70%">{$userId}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员名字</td>
- <td width="70%">{$userName}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员地址</td>
- <td width="70%">{$address}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员电话</td>
- <td width="70%">{$mobile}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单编号</td>
- <td width="70%">{$orderSn}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单日期</td>
- <td width="70%">{$orderAt}</td>
- </tr>
- <tr>
- <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">订单明细</td>
- <td class="bg"></td>
- </tr>
- </table>
- ORDER;
- $l['a_meta_charset'] = 'UTF-8';
- $l['a_meta_dir'] = 'ltr';
- $l['a_meta_language'] = 'zh';
- $l['w_page'] = '页面';
- $context = <<<ORDER
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>订单详情</title>
- <style>
- table {
- border-collapse: collapse;
- }
- table td, table th {
- border: 1px solid #ccc;
- padding: 10px 30px;
- border-collapse: collapse;
- }
- td {
- padding: 120px;
- }
- .bg {
- background-color: #ccc;
- }
- </style>
- </head>
- <body>
- <div class="content">
- <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>订单详情</b><br></p>
- <div>
- <div style="display: block; width: 100%;">
- {$orderBase}
-
- <table border="1" width="100%" style="padding: 10px 20px; text-align: center;">
- <tr>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">商品编号</th>
- <th width="30%" style="font-size: 14px; font-weight: bold; text-align: center;">商品名称</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">数量</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">单价</th>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">总价</th>
- </tr>
- {$orderDetails}
- <tr>
- <td colspan="2">合计</td>
- <td>{$orderNums}</td>
- <td></td>
- <td>{$orderAmount}</td>
- </tr>
- </table>
- </div>
-
- <div style="width: 100%; margin-top: 50px; height: 30px;">
- <table width="100%" style="border: none; padding: 10px 20px; text-align: center;">
- <tr style="border: none;">
- <td width="70%" style="border: none;"></td>
- <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">签名:</td>
- </tr>
- <tr style="border: none;">
- <td width="70%" style="border: none;"></td>
- <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">日期:</td>
- </tr>
- </table>
- </div>
- </div>
- </div>
- </body>
- </html>
- ORDER;
- require_once (\Yii::$app->vendorPath . '/tecnickcom/tcpdf/tcpdf.php');
- $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
- // 设置打印模式
- $pdf->SetCreator(PDF_CREATOR);
- $pdf->SetAuthor('DaZe');
- $pdf->SetTitle($orderSn);
- $pdf->SetSubject('TCPDF Tutorial');
- $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
- // 是否显示页眉
- $pdf->setPrintHeader(false);
- // 设置页眉字体
- $pdf->setHeaderFont(Array('dejavusans', '', '12'));
- // 页眉距离顶部的距离
- $pdf->SetHeaderMargin('5');
- // 是否显示页脚
- $pdf->setPrintFooter(false);
- // 设置默认等宽字体
- $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
- // 设置行高
- $pdf->setCellHeightRatio(1);
- // 设置左、上、右的间距
- $pdf->SetMargins('10', '10', '10');
- // 设置是否自动分页 距离底部多少距离时分页
- $pdf->SetAutoPageBreak(TRUE, '15');
- // 设置图像比例因子
- $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
- if (@file_exists(\Yii::$app->vendorPath . 'tecnickcom/tcpdf/examples/lang/eng.php')) {
- require_once(\Yii::$app->vendorPath . '/tecnickcom/tcpdf/examples/lang/eng.php');
- $pdf->setLanguageArray($l);
- }
- $pdf->setFontSubsetting(true);
- $pdf->AddPage();
- // 设置字体
- $pdf->SetFont('stsongstdlight', '', 10, '', true);
- $pdf->writeHTML($context);
- ob_clean();
- $file_name = $orderSn . '.pdf';
- $path = 'pdfs/' . $file_name;
- $pdf->Output(Yii::$app->basePath . '/web/' . $path, 'F');
- @exec('chmod -R 777 /' . Yii::$app->basePath . '/web' . $path);
- return static::notice(['fileUrl' => $path, 'targetName' => $file_name]);
- }
- }
|