| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace frontendApi\modules\v1\controllers;
- use common\helpers\Cache;
- use common\helpers\Date;
- use common\helpers\Form;
- use common\helpers\LoggerTool;
- use common\helpers\Tool;
- use common\helpers\user\Info;
- use common\models\ApproachDecOrder;
- use common\models\BaApproachDecOrder;
- use common\models\ApproachOrder;
- use common\models\ApproachOrderGoods;
- use common\models\BaApproachOrder;
- use common\models\BaApproachOrderGoods;
- use common\models\BaOrder;
- use common\models\BaOrderGoods;
- use common\models\BaReceiveAddress;
- use common\models\BaUser;
- use common\models\Countries;
- use common\models\Currency;
- use common\models\CurrencyConversions;
- use common\models\DecOrder;
- use common\models\BaDecOrder;
- use common\models\forms\ApproachAutoMaintenanceOrderForm;
- use common\models\forms\ApproachOrderForm;
- use common\models\forms\ApproachReconsumeOrderForm;
- use common\models\forms\BaApproachOrderForm;
- use common\models\forms\DeclarationForm;
- use common\models\forms\OrderForm;
- use common\models\FreeTemplate;
- use common\models\Instalment;
- use common\models\Order;
- use common\models\OrderGoods;
- use common\models\ReceiveAddress;
- use common\models\Region;
- use common\models\ShopGoods;
- use common\models\ShopGoodsNature;
- use common\models\User;
- use common\models\UserBonus;
- use common\models\UserPerformance;
- use common\models\UserWallet;
- use Yii;
- use yii\base\Exception;
- use yii\data\Pagination;
- use yii\db\Query;
- use yii\web\HttpException;
- class ShopController extends BaseController {
- public $modelClass = DecOrder::class;
- /**
- * 商品列表
- * @return mixed
- * @throws HttpException
- */
- public function actionIndex() {
- // 商品分类
- $categoryType = \Yii::$app->request->get('categoryType', 1);
- // 会员信息
- $user = User::getEnCodeInfo(\Yii::$app->user->id);
- $condition = ' AND S.STATUS=1 AND (FIND_IN_SET(2, S.GIFT_TYPE)>0';
- if ($user['IS_STUDIO'] == 1) {
- $condition.= " OR FIND_IN_SET(4,GIFT_TYPE)>0";
- }
- $condition .= ") AND S.CATEGORY_TYPE = :CATEGORY_TYPE";
- $params[':CATEGORY_TYPE'] = intval($categoryType);
- $params[':COUNTRY_ID'] = $user['COUNTRY_ID'];
- $userId = \Yii::$app->user->id;
- // 分期的总期数
- $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
- // 查询是否有BD的分期订单
- $stageBD = Instalment::getOneStage($userId, 'BD');
- if ($stageBD && $stageBD < $instalmentConfig) {
- $condition .= " AND INSTALMENT = 0";
- } else {
- // 查询是否有FX的分期订单
- $stageFX = Instalment::getOneStage($userId, 'FX');
- if ($stageFX && $stageFX < $instalmentConfig) {
- $condition .= " AND (INSTALMENT = 0 OR INSTALMENT=" . ($stageFX + 1) . ")";
- } else {
- $condition .= " AND (INSTALMENT = 0 OR INSTALMENT=1)";
- }
- }
- $condition .= ' AND N.COUNTRY_ID=:COUNTRY_ID ';
- $data = ShopGoods::lists($condition, $params, [
- 'select' => 'S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID',
- 'from' => ShopGoods::tableName() . ' AS S',
- 'join' => [
- ['INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID = S.ID'],
- ],
- 'orderBy' => 'S.SORT ASC, S.CREATED_AT DESC',
- ]);
- $currencies = Currency::getAllData();
- $currencies = array_column($currencies, NULL, 'ID');
- foreach ($data['list'] as $key => $value) {
- $data['list'][$key]['DISCOUNT'] = in_array($value['TYPE'], [1, 2]) ? ShopGoods::getGoodType()[$value['TYPE']]['discount'] : $value['SELL_DISCOUNT'] * 100;
- $data['list'][$key]['COIN'] = $currencies[$value['LOCAL_CURRENCY_ID']]['CODE'] ?? '';
- }
-
- return static::notice($data);
- }
- /**
- * 获取商品详情
- * @return mixed
- * @throws 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 HttpException
- */
- public function actionShowCart(){
- // 会员信息
- $user = User::getEnCodeInfo(\Yii::$app->user->id);
- $payList = ShopGoods::payTypes();
- $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID AND COUNTRY_ID=:COUNTRY_ID',
- [':USER_ID' => $user['ID'], ':COUNTRY_ID' => $user['COUNTRY_ID']]);
- 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']);
- }
- }
- // 账户币种
- $country = Countries::getById($user['COUNTRY_ID']);
- $coin = Currency::getById($country['LOCAL_CURRENCY_ID']);
- $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
- $decCountry = Countries::getById($decCountryId);
- $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
- $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
- $userBalance = [
- 'cash' => 0,
- 'prp' => 0,
- 'localCash' => 0,
- 'localRrp' => 0,
- ];
- if ($userCashResult = UserWallet::findOneAsArray(['USER_ID' => $user['ID']])) {
- $userBalance['cash'] = $userCashResult['CASH'];
- $userBalance['localCash'] = Tool::convertAmount($userCashResult['CASH'], $decUserCurrencyRate, $currencyRate);
- }
- if ($userPerformance = UserPerformance::getAmounts($user['ID'])) {
- $userBalance['prp'] = $userPerformance;
- $userBalance['localCash'] = Tool::convertAmount($userPerformance, $decUserCurrencyRate, $currencyRate);
- }
- // 运费模板
- $freeTemplate = FreeTemplate::getByCountryId($user['COUNTRY_ID']);
- // 运费
- $freight = $freeTemplate['freight'] ?? 0;
- // 免运费阈值
- $freeShipping = $freeTemplate['free_shipping'] ?? 0;
- $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
- // 账户币种
- $country = Countries::getById($user['COUNTRY_ID']);
- $coin = Currency::getById($country['LOCAL_CURRENCY_ID']);
- // AMP
- $sysConfig = Cache::getSystemConfig();
- $ampDivideLine = (int)$sysConfig['ampBVCondition']['VALUE'];
- return static::notice(
- [
- 'payList'=>$payList,
- 'allAddress'=>$allAddress,
- 'userBalance'=>$userBalance,
- 'sellType' => ShopGoods::getCategoryType(),
- 'freight' => $freight,
- 'freeShipping' => $freeShipping,
- 'isDec' => $isDec,
- 'coin' => $coin['CODE'] ?? '',
- 'ampDivideLine' => floatval($ampDivideLine),
- ]);
- }
- /**
- * 确认订单
- */
- public function actionSureOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderForm();
- $formModel->scenario = 'userOrder';
- $formModel->remark = 'FX';//复销备注
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
- $stockist = $post['userName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- if($loginUserInfo['IS_DEC'] == 1 && $stockist != $loginUserInfo['USER_NAME']){
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- if($loginUserInfo['IS_DEC'] == 0){
- //查询报单编号是否存在
- $stockistId = Info::getUserIdByUserName($stockist);
- if(!$stockistId){
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- $isDec = User::getEnCodeInfo($stockistId)['IS_DEC'];
- if(!$isDec){
- return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
- }
- }
- $formModel->decUserName = $stockist;
- if ($formModel->load($post, '') && $order = $formModel->add()) {
- return static::notice($order);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * 订单支付成功
- * @throws 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);
- }
- /**
- * 确认订单
- */
- public function actionSureApproachOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new ApproachOrderForm();
- $formModel->scenario = 'userOrder';
- $formModel->remark = '复销备注';
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $loginUserInfo = User::getEnCodeInfo(\Yii::$app->user->id);
- $stockist = $post['userName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- if($loginUserInfo['IS_DEC'] == 1 && !empty($post['userName']) && $post['userName'] != $loginUserInfo['USER_NAME']){
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- //查询报单编号是否存在
- if($loginUserInfo['IS_DEC'] == 0){
- $userId = Info::getUserIdByUserName($post['userName']);
- if(!$userId){
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
- if(!$isDec){
- return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
- }
- }
- $formModel->decUserName = $post['userName'];
- if ($formModel->load($post, '') && $order = $formModel->add()) {
- return static::notice($order);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * 确认复消订单
- */
- public function actionSureApproachReconsumeOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new ApproachReconsumeOrderForm();
- $formModel->scenario = 'reconsumeOrder';
- $formModel->remark = Yii::t('app', 'reconsume');
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $stockist = $post['userName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- if ($formModel->load($post, '') && $order = $formModel->add()) {
- return static::notice($order);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * PayStack支付成功的webhook.
- * @throws HttpException
- * @throws \Exception
- */
- public function actionVerifyApproachOrder() {
- if (\Yii::$app->request->isPost) {
- $request = \Yii::$app->request->post();
- LoggerTool::notice($request);
- // 支付webhook回调日志
- Tool::approachOrderCall($request);
- try {
- $data = $request['data'];
- $status = $request['data']['status'] ?? 'false';
- // 订单状态
- $orderStatus = ($status == 'success') ? \Yii::$app->params['orderStatus']['paid']['value'] : \Yii::$app->params['orderStatus']['failPaid']['value'];
- $customFields = $data['metadata']['custom_fields'] ?? [];
- $oderSn = $customFields[0]['value'] ?? '';
- $orderType = $customFields[1]['value'] ?? false;
- $formModel = new ApproachOrderForm();
- $formModel->scenario = 'verifyPayStack';
- $load = [
- 'sn' => $oderSn,
- 'scenario' => 'verifyPayStack',
- 'status' => $orderStatus,
- 'note' => [
- 'id' => $data['id'],
- 'domain' => $data['domain'],
- 'status' => $data['status'],
- 'reference' => $data['reference'],
- 'amount' => $data['amount'],
- 'created_at' => $data['created_at'],
- 'paid_at' => $data['paid_at'],
- 'channel' => $data['channel'],
- 'currency' => $data['currency'],
- 'ip_address' => $data['ip_address'],
- 'metadata' => $data['metadata'],
- 'customer' => $data['customer'],
- 'email' => $data['customer']['email'] ?? '',
- ],
- ];
- if ($formModel->load($load, '') && $order = $formModel->verifyPayStack()) {
- LoggerTool::error($order);
- return http_response_code(200);
- } else {
- LoggerTool::error(Form::formatErrorsForApi($formModel->getErrors()));
- return http_response_code(500);
- }
- } catch (\Exception $e) {
- LoggerTool::error(sprintf('actionVerifyApproachOrderError: File[%s], Line:[%s], Message[%s]', $e->getFile(), $e->getLine(), $e->getMessage()));
- return http_response_code(500);
- }
- }
- return http_response_code(200);
- }
- /**
- * 删除准订单
- */
- public function actionDeleteApproachOrder()
- {
- $orderSn = \Yii::$app->request->post('orderSn');
- // 删除订单中间表
- ApproachOrder::deleteAll('SN = :SN', [':SN' => $orderSn]);
- // 删除订单商品中间表
- ApproachOrderGoods::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $orderSn]);
- // 删除报单中间表
- ApproachDecOrder::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $orderSn]);
- return static::notice('');
- }
- /**
- * @throws HttpException
- */
- public function actionDecOrderList() {
- $version = \Yii::$app->request->get('v');
- $data = $version == 2 ? $this->decOrderListV2() : $this->decOrderListV1();
- return static::notice($data);
- }
- /**
- * 我的报单
- * @return mixed
- * @throws HttpException
- */
- public function decOrderListV1() {
- $condition = ' DO.USER_ID=:USER_ID AND DO.IS_DEL=0';
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = DecOrder::find()
- ->alias('DO')
- ->where($condition, $params)
- ->select('DO.*,O.STATUS,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.SKU_CODE,OG.GOODS_TITLE,OG.BUY_NUMS,OG.REAL_PRICE,OG.REAL_PV,OG.TAX_RATE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN')
- ->join('LEFT JOIN', Order::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = ApproachDecOrder::find()
- ->alias('DO')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('DO.*,O.STATUS,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.SKU_CODE,OG.GOODS_TITLE,OG.BUY_NUMS,OG.REAL_PRICE,OG.REAL_PV,OG.TAX_RATE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', ApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN')
- ->join('LEFT JOIN', ApproachOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as &$value) {
- $value['TAX_AMOUNT'] = Tool::calculateTax($value['REAL_PRICE'], floatval($value['TAX_RATE']), intval($value['BUY_NUMS']));
- $value['STATUS'] = Tool::paramConvert(\Yii::$app->params['orderStatus'])[$value['STATUS']]['label'] ?? '';
- $value['CREATED_AT'] = $value['CREATED_AT'] ? Date::convert($value['CREATED_AT'],'Y-m-d H:i:s') : '';
- $value['REAL_PV'] = Tool::formatPrice($value['REAL_PV'] * $value['BUY_NUMS']);
- $value['TOTAL_AMOUNT'] = Tool::formatPrice($value['REAL_PRICE'] * $value['BUY_NUMS']);
- }
- return $data;
- }
- /**
- * 我的报单
- * @return mixed
- * @throws HttpException
- */
- public function decOrderListV2() {
- $condition = ' DO.USER_ID=:USER_ID AND DO.IS_DEL=0';
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = DecOrder::find()
- ->alias('DO')
- ->where($condition, $params)
- ->select('DO.DEC_SN,DO.ORDER_SN,DO.CREATED_AT,O.STATUS,O.CONSIGNEE,O.MOBILE,O.PAY_TYPE,O.PAY_AT,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,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')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', Order::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = ApproachDecOrder::find()
- ->alias('DO')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('DO.DEC_SN,DO.ORDER_SN,DO.CREATED_AT,O.STATUS,O.CONSIGNEE,O.MOBILE,O.PAY_TYPE,O.PAY_AT,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,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')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', ApproachOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as &$value) {
- if (($value['PAY_TYPE'] == 'pay_stack') && in_array($value['STATUS'], [\Yii::$app->params['orderStatus']['notPaid']['value'], \Yii::$app->params['orderStatus']['failPaid']['value']])) {
- // 订单中间表
- $orderGoods = ApproachOrderGoods::findAllAsArray('ORDER_SN=:ORDER_SN', [':ORDER_SN' => $value['ORDER_SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- } else {
- // 订单表
- $orderGoods = OrderGoods::findAllAsArray('ORDER_SN=:ORDER_SN', [':ORDER_SN' => $value['ORDER_SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- }
- $value['hasChildren'] = $orderGoods;
- $value['PAY_TYPE'] = array_column(ShopGoods::getSaleType(), NULL, 'label')[$value['PAY_TYPE']]['name'] ?? '';
- $value['STATUS'] = Tool::paramConvert(\Yii::$app->params['orderStatus'])[$value['STATUS']]['label'] ?? '';
- $value['CREATED_AT'] = $value['CREATED_AT'] ? Date::convert($value['CREATED_AT'],'Y-m-d H:i:s') : '';
- $value['FULL_ADDRESS'] = trim(implode(', ', [$value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], Region::getCnName($value['PROVINCE'])]), ', ');
- unset($value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], $value['PROVINCE']);
- }
- return $data;
- }
- /**
- * 我的订单.(自己复消+自己加入时的首单)
- * 创建人是自己+USER_ID是自己的复消单、创建人不是自己+USER_ID是自己的报单
- * @throws HttpException
- */
- public function actionOwnOrder() {
- $uname = Info::getUserNameByUserId(\Yii::$app->user->id);
- $condition = " O.USER_ID=:USER_ID AND O.USER_NAME='{$uname}' AND O.IS_DELETE = 0";
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = Order::find()
- ->alias('O')
- ->where($condition, $params)
- ->select('O.ID,O.SN,O.USER_NAME,O.ORDER_TYPE,O.ORDER_AMOUNT,O.STATUS,O.CREATED_AT,O.PAY_TYPE,O.PAY_AT,O.CONSIGNEE,O.MOBILE,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,U.REAL_NAME,O.COUNTRY_ID,O.CURRENCY_ID,C.CODE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', Currency::tableName() . ' AS C', 'C.ID=O.CURRENCY_ID');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = ApproachOrder::find()
- ->alias('O')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('O.ID,O.SN,O.USER_NAME,O.ORDER_TYPE,O.ORDER_AMOUNT,O.STATUS,O.CREATED_AT,O.PAY_TYPE,O.PAY_AT,O.CONSIGNEE,O.MOBILE,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,U.REAL_NAME,O.COUNTRY_ID,O.CURRENCY_ID,C.CODE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', Currency::tableName() . ' AS C', 'C.ID=O.CURRENCY_ID');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as $key => $value) {
- if (($value['PAY_TYPE'] == 'pay_stack') && in_array($value['STATUS'], [\Yii::$app->params['orderStatus']['notPaid']['value'], \Yii::$app->params['orderStatus']['failPaid']['value']])) {
- // 订单中间表
- $orderGoods = ApproachOrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- } else {
- // 订单表
- $orderGoods = OrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- }
- $data['list'][$key]['hasChildren'] = $orderGoods;
- $data['list'][$key]['ORDER_TYPE'] = $value['ORDER_TYPE']=='ZC' ? 'Welcome Pack' : (in_array($value['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Repeat Purchase': 'Points');
- $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]['FULL_ADDRESS'] = trim(implode(', ', [$value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], Region::getCnName($value['PROVINCE'])]), ', ');
- $data['list'][$key]['SHOW_BV'] = !in_array($value['PAY_TYPE'], [5, 6]);
- $data['list'][$key]['COUNTRY'] = Countries::getById($value['COUNTRY_ID'])['NAME'];
- $data['list'][$key]['CURRENCY'] = Currency::getById($value['CURRENCY_ID'])['CODE'];
- unset($data['list'][$key]['ADDRESS'], $data['list'][$key]['CITY_NAME'], $data['list'][$key]['LGA_NAME'], $data['list'][$key]['PROVINCE']);
- }
- return static::notice($data);
- }
- /**
- * 会员订单.(给别人复消、给别人报单、给别人升级)
- * 给别人复消:创建人是自己、USER_ID不是自己、ORDER_TYPE=FX
- * 给别人报单:创建人是自己、USER_ID是自己、ORDER_TYPE=ZC、收货人不是自己
- * 给别人升级:创建人是自己、USER_ID不是自己、ORDER_TYPE=ZC
- */
- public function actionMemberOrder() {
- $uname = Info::getUserNameByUserId(\Yii::$app->user->id);
- $condition = " O.USER_ID<>:USER_ID AND O.USER_NAME<>'{$uname}' AND O.CREATE_USER='{$uname}' AND O.IS_DELETE = 0";
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = Order::find()
- ->alias('O')
- ->where($condition, $params)
- ->select('O.ID,O.SN,O.USER_NAME,O.ORDER_TYPE,O.ORDER_AMOUNT,O.STATUS,O.CREATED_AT,O.PAY_TYPE,O.PAY_AT,O.CONSIGNEE,O.MOBILE,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,U.REAL_NAME,O.COUNTRY_ID,O.CURRENCY_ID,C.CODE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', Currency::tableName() . ' AS C', 'C.ID=O.CURRENCY_ID');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = ApproachOrder::find()
- ->alias('O')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('O.ID,O.SN,O.USER_NAME,O.ORDER_TYPE,O.ORDER_AMOUNT,O.STATUS,O.CREATED_AT,O.PAY_TYPE,O.PAY_AT,O.CONSIGNEE,O.MOBILE,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,U.REAL_NAME,O.COUNTRY_ID,O.CURRENCY_ID,C.CODE')
- ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', Currency::tableName() . ' AS C', 'C.ID=O.CURRENCY_ID');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as $key => $value) {
- if (($value['PAY_TYPE'] == 'pay_stack') && in_array($value['STATUS'], [\Yii::$app->params['orderStatus']['notPaid']['value'], \Yii::$app->params['orderStatus']['failPaid']['value']])) {
- // 订单中间表
- $orderGoods = ApproachOrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- } else {
- // 订单表
- $orderGoods = OrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- }
- $data['list'][$key]['hasChildren'] = $orderGoods;
- $data['list'][$key]['ORDER_TYPE'] = $value['ORDER_TYPE']=='ZC' ? 'Welcome Pack' : (in_array($value['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Repeat Purchase': 'Points');
- $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]['FULL_ADDRESS'] = trim(implode(', ', [$value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], Region::getCnName($value['PROVINCE'])]), ', ');
- $data['list'][$key]['SHOW_BV'] = !in_array($value['PAY_TYPE'], [5, 6]);
- $data['list'][$key]['COUNTRY'] = Countries::getById($value['COUNTRY_ID'])['NAME'];
- $data['list'][$key]['CURRENCY'] = Currency::getById($value['CURRENCY_ID'])['CODE'];
- unset($data['list'][$key]['ADDRESS'], $data['list'][$key]['CITY_NAME'], $data['list'][$key]['LGA_NAME'], $data['list'][$key]['PROVINCE']);
- }
- return static::notice($data);
- }
- /**
- * 会员复消
- */
- public function actionReconsume() {
- // 会员信息
- $user = User::findOneAsArray('ID=:ID', [':ID' => \Yii::$app->request->get('userId')]);
- if (!$user) {
- return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
- }
- $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0 OR FIND_IN_SET(4,GIFT_TYPE)>0) AND N.COUNTRY_ID=:COUNTRY_ID';
- $data = ShopGoods::lists($condition, [':COUNTRY_ID' => $user['COUNTRY_ID']], [
- 'select' => 'S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID',
- 'from' => ShopGoods::tableName() . ' AS S',
- 'join' => [
- ['INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID = S.ID'],
- ],
- 'orderBy' => 'SORT ASC,CREATED_AT DESC',
- 'limit' => 100,
- ]);
- $currencies = Currency::getAllData();
- $currencies = array_column($currencies, NULL, 'ID');
- foreach ($data['list'] as $key => $value) {
- $data['list'][$key]['DISCOUNT'] = in_array($value['TYPE'], [1, 2]) ? ShopGoods::getGoodType()[$value['TYPE']]['discount'] : $value['SELL_DISCOUNT'] * 100;
- $data['list'][$key]['COIN'] = $currencies[$value['LOCAL_CURRENCY_ID']]['CODE'] ?? '';
- }
- return static::notice($data);
- }
- /**
- * 帮会员复消购物车
- * @throws HttpException
- */
- public function actionReconsumeCart(){
- // 收货会员
- $user = User::findOneAsArray('ID=:ID', [':ID' => \Yii::$app->request->get('userId')]);
- if (!$user) {
- return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
- }
- // 汇率
- $afterCountry = Countries::getById($user['COUNTRY_ID']);
- $afterCurrency = CurrencyConversions::getToUSDRate($afterCountry['LOCAL_CURRENCY_ID']);
- // 登录会员
- $userId = \Yii::$app->user->id;
- $userData = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
- // 会员不能给自己复销
- if (\Yii::$app->request->get('userId') == $userId) {
- return static::notice(Yii::t('app', 'memberCanNotPayoutOfSelf'), 400);
- }
- // 汇率
- $beforeCountry = Countries::getById($userData['COUNTRY_ID']);
- $beforeCurrency = CurrencyConversions::getToUSDRate($beforeCountry['LOCAL_CURRENCY_ID']);
- $payList = ['cash'=>['name'=>'Account Balance'],];//余额支付
- $userBalance = [
- 'points' => 0,
- 'cash' => 0
- ];
- if ($userBonusResult = UserBonus::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['points'] = Tool::convertAmount($userBonusResult['RECONSUME_POINTS'], $beforeCurrency, $afterCurrency);
- }
- if ($userCashResult = UserWallet::findOneAsArray(['USER_ID' => $userId])) {
- $userBalance['cash'] = Tool::convertAmount($userCashResult['CASH'], $beforeCurrency, $afterCurrency);
- }
- return static::notice(['payList'=>$payList,'userBalance'=>$userBalance]);
- }
- /**
- * 帮会员复消确认订单
- */
- public function actionReconsumeSureOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderForm();
- $formModel->scenario = 'reconsumeOrder';
- $formModel->remark = Yii::t('app', 'reconsume');
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $stockist = $post['decUserName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- if ($formModel->load($post, '') && $formModel->reconsumeAdd()) {
- return static::notice(Yii::t('app', 'reconsumeSuccessfully'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- }
- /**
- * 商品列表tabs分类
- * @return mixed
- * @throws HttpException
- */
- public function actionGoodsActive()
- {
- $data = [
- // [
- // 'name' => 'bonus',
- // 'label' => '奖金商品',
- // ],
- [
- 'name' => '1',
- 'label' => Yii::t('app', 'standardProducts'),
- ],
- // [
- // 'name' => '4',
- // 'label' => Yii::t('app', 'travelFundProducts'),
- // ],
- [
- 'name' => '5',
- 'label' => Yii::t('app', 'carFundProducts'),
- ],
- [
- 'name' => '6',
- 'label' => Yii::t('app', 'villaFundProducts'),
- ],
- ];
- return static::notice($data);
- }
- /**
- * 导出订单.
- * @return mixed
- * @throws HttpException
- * @throws \Mpdf\MpdfException
- */
- public function actionOrderExport()
- {
- $uname = Info::getUserNameByUserId(\Yii::$app->user->id);
- $orderSn = \Yii::$app->request->get('orderSn');
- $condition = " AND SN=:SN AND O.IS_DELETE = 0";
- $params = [
- ':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'],
- ],
- ]);
- if (!$data['list']) {
- $condition .= ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)';
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $data = ApproachOrder::lists($condition, $params, [
- 'select' => 'O.*,U.REAL_NAME,OG.*,OG.CATEGORY_TYPE',
- 'orderBy' => 'O.CREATED_AT DESC',
- 'from' => ApproachOrder::tableName() . ' AS O',
- 'join' => [
- ['LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID'],
- ['LEFT JOIN', ApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN'],
- ],
- ]);
- }
- $userId = '';
- $userName = '';
- $address = '';
- $mobile = '';
- $orderAt = '';
- $orderDetails = '';
- $orderAmount = 0; // 合计总额
- $orderNums = 0; // 合计总数
- $totalTaxAmount = 0; // 合计税额
- $totalAmount = 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['CREATED_AT'],'Y-m-d H:i:s');
- // 总价
- $totalAmount = $value['BUY_NUMS'] * $value['REAL_PRICE'];
- $orderAmount += $totalAmount;
- $orderNums += $value['BUY_NUMS'];
- // 税额
- $taxAmount = floatval(Tool::formatPrice(($value['REAL_PRICE'] - ($value['REAL_PRICE'] / (1 + $value['TAX_RATE'] / 100))) * $value['BUY_NUMS']));
- $totalTaxAmount += $taxAmount;
- $productAmount = Tool::formatAmount($value['REAL_PRICE']);
- $taxAmount = Tool::formatAmount($taxAmount);
- $totalAmount = Tool::formatAmount($totalAmount);
- // 订单详情
- $orderDetails .= <<<EOT
- <tr>
- <td style="text-align: center;">{$value['SKU_CODE']}</td>
- <td style="text-align: center;">{$value['GOODS_TITLE']}</td>
- <td style="text-align: right;">{$productAmount}</td>
- <td style="text-align: right;">{$value['BUY_NUMS']}</td>
- <td style="text-align: right;">{$value['TAX_RATE']}%</td>
- <td style="text-align: right;">{$taxAmount}</td>
- <td style="text-align: right;">{$totalAmount}</td>
- </tr>
- EOT;
- }
- $memberCode = Yii::t('app', 'memberCode');
- $memberName = Yii::t('app', 'memberName');
- $memberAddress = Yii::t('app', 'memberAddress');
- $memberPhone = Yii::t('app', 'memberPhone');
- $orderCode = Yii::t('app', 'orderCode');
- $orderDetail = Yii::t('app', 'orderDetail');
- $productCode = Yii::t('app', 'productCode');
- $productName = Yii::t('app', 'productName');
- $productPrice = Yii::t('app', 'productPrice');
- $quantity = Yii::t('app', 'qty');
- $taxRate = Yii::t('app', 'taxRate');
- $totalTax = Yii::t('app', 'totalTax');
- $totalAmount = Yii::t('app', 'totalAmount');
- $total = Yii::t('app', 'total');
- $signature = Yii::t('app', 'signature');
- $date = Yii::t('app', 'date');
- $createAt = Yii::t('app', 'createAt');
- // 订单基本信息
- $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;">{$memberCode}</td>
- <td width="70%">{$userId}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberName}</td>
- <td width="70%">{$userName}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberAddress}</td>
- <td width="70%">{$address}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberPhone}</td>
- <td width="70%">{$mobile}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$orderCode}</td>
- <td width="70%">{$orderSn}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$createAt}</td>
- <td width="70%">{$orderAt}</td>
- </tr>
- <tr>
- <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">{$orderDetail}</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'] = '页面';
- $orderAmount = Tool::formatAmount($orderAmount);
- $totalTaxAmount = Tool::formatAmount($totalTaxAmount);
- $context = <<<ORDER
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>{$orderDetail}</title>
- <style>
- table {
- border-collapse: collapse;
- }
- table td, table th {
- border: 1px solid #ccc;
- /*padding: 5px 5px;*/
- 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>{$orderDetail}</b><br></p>
- <div>
- <div style="display: block; width: 100%;">
- {$orderBase}
-
- <table border="1" width="100%" style="padding: 10px 5px; text-align: center;">
- <tr>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productCode}</th>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productName}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productPrice}</th>
- <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">{$quantity}</th>
- <th width="12%" style="font-size: 14px; font-weight: bold; text-align: center;">{$taxRate}</th>
- <th width="13%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalTax}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalAmount}</th>
- </tr>
- {$orderDetails}
- <tr>
- <td colspan="3">{$total}</td>
- <td style="text-align: right;">{$orderNums}</td>
- <td></td>
- <td style="text-align: right;">{$totalTaxAmount}</td>
- <td style="text-align: right;">{$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;">{$signature}:</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;">{$date}:</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', '0', '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);
- // $image_file = \Yii::$app->basePath . '/../frontendEle/src/static/img/ngds-logo.jpg';
- // if (!file_exists($image_file)) {
- // $image_file = \Yii::$app->runtimePath . '/../common/uploads/ngds-logo.jpg';
- // }
- $image_file = \Yii::$app->runtimePath . '/../ngds-logo.jpg';
- $image = file_get_contents($image_file);
- $pdf->Image('@' . $image, 15, 12, 20, 7, 'JPG');
- $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 HttpException
- */
- 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'],
- ],
- ]);
- if (!$data['list']) {
- $data = ApproachDecOrder::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' => ApproachDecOrder::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', ApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN'],
- ['LEFT JOIN', ApproachOrder::tableName() . ' AS OD', 'OD.SN=DO.ORDER_SN'],
- ],
- ]);
- }
- $userId = '';
- $userName = '';
- $address = '';
- $mobile = '';
- $orderAt = '';
- $orderDetails = '';
- $orderAmount = 0; // 合计总额
- $orderNums = 0; // 合计总数
- $totalTaxAmount = 0; // 合计税额
- $totalAmount = 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['CREATED_AT'],'Y-m-d H:i:s');
- // 总价
- $totalAmount = $value['BUY_NUMS'] * $value['REAL_PRICE'];
- $orderAmount += $totalAmount;
- $orderNums += $value['BUY_NUMS'];
- // 税额
- $taxAmount = floatval(Tool::formatPrice(($value['REAL_PRICE'] - ($value['REAL_PRICE'] / (1 + $value['TAX_RATE'] / 100))) * $value['BUY_NUMS']));
- $totalTaxAmount += $taxAmount;
- $taxAmount = sprintf('%.2f', $taxAmount);
- $totalAmount = sprintf('%.2f', $totalAmount);
- // 订单详情
- $orderDetails .= <<<EOT
- <tr>
- <td style="text-align: center;">{$value['SKU_CODE']}</td>
- <td style="text-align: center;">{$value['GOODS_TITLE']}</td>
- <td style="text-align: right;">{$value['REAL_PRICE']}</td>
- <td style="text-align: right;">{$value['BUY_NUMS']}</td>
- <td style="text-align: right;">{$value['TAX_RATE']}%</td>
- <td style="text-align: right;">{$taxAmount}</td>
- <td style="text-align: right;">{$totalAmount}</td>
- </tr>
- EOT;
- }
- $memberCode = Yii::t('app', 'memberCode');
- $memberName = Yii::t('app', 'memberName');
- $memberAddress = Yii::t('app', 'memberAddress');
- $memberPhone = Yii::t('app', 'memberPhone');
- $orderCode = Yii::t('app', 'orderCode');
- $orderDetail = Yii::t('app', 'orderDetail');
- $productCode = Yii::t('app', 'productCode');
- $productName = Yii::t('app', 'productName');
- $productPrice = Yii::t('app', 'productPrice');
- $quantity = Yii::t('app', 'qty');
- $taxRate = Yii::t('app', 'taxRate');
- $totalTax = Yii::t('app', 'totalTax');
- $totalAmount = Yii::t('app', 'totalAmount');
- $total = Yii::t('app', 'total');
- $signature = Yii::t('app', 'signature');
- $date = Yii::t('app', 'date');
- $createAt = Yii::t('app', 'createAt');
- // 订单基本信息
- $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;">{$memberCode}</td>
- <td width="70%">{$userId}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberName}</td>
- <td width="70%">{$userName}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberAddress}</td>
- <td width="70%">{$address}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberPhone}</td>
- <td width="70%">{$mobile}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$orderCode}</td>
- <td width="70%">{$orderSn}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$createAt}</td>
- <td width="70%">{$orderAt}</td>
- </tr>
- <tr>
- <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">{$orderDetail}</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'] = '页面';
- $orderAmount = sprintf('%.2f', $orderAmount);
- $totalTaxAmount = sprintf('%.2f', $totalTaxAmount);
- $context = <<<ORDER
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>{$orderDetail}</title>
- <style>
- table {
- border-collapse: collapse;
- }
- table td, table th {
- border: 1px solid #ccc;
- /*padding: 5px 5px;*/
- 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>{$orderDetail}</b><br></p>
- <div>
- <div style="display: block; width: 100%;">
- {$orderBase}
-
- <table border="1" width="100%" style="padding: 10px 5px; text-align: center;">
- <tr>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productCode}</th>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productName}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productPrice}</th>
- <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">{$quantity}</th>
- <th width="12%" style="font-size: 14px; font-weight: bold; text-align: center;">{$taxRate}</th>
- <th width="13%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalTax}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalAmount}</th>
- </tr>
- {$orderDetails}
- <tr>
- <td colspan="3">{$total}</td>
- <td style="text-align: right;">{$orderNums}</td>
- <td></td>
- <td style="text-align: right;">{$totalTaxAmount}</td>
- <td style="text-align: right;">{$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;">{$signature}:</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;">{$date}:</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', '0', '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);
- // $image_file = \Yii::$app->basePath . '/../frontendEle/src/static/img/ngds-logo.jpg';
- // if (!file_exists($image_file)) {
- // $image_file = \Yii::$app->runtimePath . '/../common/uploads/ngds-logo.jpg';
- // }
- $image_file = \Yii::$app->runtimePath . '/../ngds-logo.jpg';
- $image = file_get_contents($image_file);
- $pdf->Image('@' . $image, 15, 12, 20, 7, 'JPG');
- $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]);
- }
- /**
- * 下载申请退货单
- */
- public function actionOrderBackingOut()
- {
- $file_name = 'orderBackingOut.xlsx';
- return static::notice(['fileUrl' => $file_name]);
- }
- /**
- * BA商品列表
- * @return mixed
- * @throws HttpException
- */
- public function actionBaProductList() {
- // 商品分类
- $categoryType = \Yii::$app->request->get('categoryType', 1);
- $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0';
- $isStudio = BaUser::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::getGoodType()[$value['TYPE']]['discount'];
- } else {
- $data['list'][$key]['DISCOUNT'] = $value['SELL_DISCOUNT']*100;
- }
- }
- return static::notice($data);
- }
- /**
- * BA购物车订单展示
- * @throws HttpException
- */
- public function actionBaShoppingCart()
- {
- // 收货地址
- $allAddress = BaReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
- 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']);
- }
- }
- // 运费.奈拉
- $freight = floatval(Cache::getSystemConfig()['freight']['VALUE'] ?? 0);
- // 普通商品免运费阈值.奈拉
- $freeShipping = floatval(Cache::getSystemConfig()['freeShipping']['VALUE'] ?? 0);
- return static::notice([
- 'freight' => $freight,
- 'freeShipping' => $freeShipping,
- 'allAddress' => $allAddress,
- ]);
- }
- /**
- * 确认BA订单
- * @throws HttpException|\yii\base\Exception
- */
- public function actionBaSureApproachOrder()
- {
- if (\Yii::$app->request->isPost) {
- $formModel = new BaApproachOrderForm();
- $formModel->scenario = 'userOrder';
- $formModel->remark = Yii::t('app', 'reconsumeRemark');
- $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);
- }
- }
- }
- /**
- * 删除BA准订单
- * @throws HttpException
- */
- public function actionBaDeleteApproachOrder()
- {
- $orderSn = \Yii::$app->request->post('orderSn');
- // 删除订单中间表
- BaApproachOrder::deleteAll('SN = :SN', [':SN' => $orderSn]);
- // 删除订单商品中间表
- BaApproachOrderGoods::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $orderSn]);
- return static::notice('');
- }
- /**
- * BA订单
- * @return mixed
- * @throws HttpException
- */
- public function actionBaOrderList()
- {
- $uname = Info::getBaUserNameByUserId(\Yii::$app->user->id);
- $condition = " (USER_ID=:USER_ID OR CREATE_USER='$uname') AND O.IS_DELETE = 0";
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = BaOrder::find()
- ->alias('O')
- ->where($condition, $params)
- ->select('O.*,U.REAL_NAME,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
- ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
- ->orderBy('O.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = BaApproachOrder::find()
- ->alias('O')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('O.*,U.REAL_NAME,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
- ->join('LEFT JOIN', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
- ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
- ->orderBy('O.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as $key => $value) {
- $data['list'][$key]['ORDER_TYPE'] = 'Reselling';
- $data['list'][$key]['PAY_AT'] = $value['PAY_AT'] ? Date::convert($value['PAY_AT'],'Y-m-d H:i:s') : '';
- $data['list'][$key]['CREATED_AT'] = $value['CREATED_AT'] ? Date::convert($value['CREATED_AT'],'Y-m-d H:i:s') : '';
- $data['list'][$key]['PAY_TYPE'] = array_column(ShopGoods::getSaleType(), NULL, 'label')[$value['PAY_TYPE']]['name'] ?? '';
- $data['list'][$key]['STATUS'] = Tool::paramConvert(\Yii::$app->params['orderStatus'])[$value['STATUS']]['label'] ?? '';
- $data['list'][$key]['FULL_ADDRESS'] = $value['ADDRESS'];
- $data['list'][$key]['TAX_AMOUNT'] = Tool::formatPrice(($value['REAL_PRICE'] - $value['REAL_PRICE'] / (1 + $value['TAX_RATE'] / 100)) * $value['BUY_NUMS']);
- $data['list'][$key]['TOTAL_AMOUNT'] = Tool::formatPrice($value['REAL_PRICE'] * $value['BUY_NUMS']);
- if ($value['LGA_NAME']) {
- $data['list'][$key]['FULL_ADDRESS'] .= ', ' . $value['LGA_NAME'];
- }
- }
- return static::notice($data);
- }
- /**
- * @throws HttpException
- */
- public function actionBaDecOrderList() {
- $version = \Yii::$app->request->get('v');
- $data = $version == 2 ? $this->baDecOrderListV2() : $this->baDecOrderListV1();
- return static::notice($data);
- }
- /**
- * 我的BA报单
- * @return mixed
- * @throws HttpException
- */
- public function baDecOrderListV1() {
- $condition = ' DO.USER_ID=:USER_ID AND DO.IS_DEL=0';
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = BaDecOrder::find()
- ->alias('DO')
- ->where($condition, $params)
- ->select('DO.*,O.STATUS,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.SKU_CODE,OG.GOODS_TITLE,OG.BUY_NUMS,OG.REAL_PRICE,OG.REAL_PV,OG.TAX_RATE')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN')
- ->join('LEFT JOIN', BaOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = BaApproachDecOrder::find()
- ->alias('DO')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('DO.*,O.STATUS,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.SKU_CODE,OG.GOODS_TITLE,OG.BUY_NUMS,OG.REAL_PRICE,OG.REAL_PV,OG.TAX_RATE')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN')
- ->join('LEFT JOIN', BaApproachOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as &$value) {
- $value['TAX_AMOUNT'] = Tool::calculateTax($value['REAL_PRICE'], floatval($value['TAX_RATE']), intval($value['BUY_NUMS']));
- $value['STATUS'] = \Yii::$app->params['orderStatus'][$value['STATUS']]['label'] ?? '';
- $value['CREATED_AT'] = $value['CREATED_AT'] ? Date::convert($value['CREATED_AT'],'Y-m-d H:i:s') : '';
- $value['REAL_PV'] = Tool::formatPrice($value['REAL_PV'] * $value['BUY_NUMS']);
- $value['TOTAL_AMOUNT'] = Tool::formatPrice($value['REAL_PRICE'] * $value['BUY_NUMS']);
- }
- return $data;
- }
- /**
- * 我的BA报单
- * @return mixed
- * @throws HttpException
- */
- public function baDecOrderListV2() {
- $condition = ' DO.USER_ID=:USER_ID AND DO.IS_DEL=0';
- $params[':USER_ID'] = \Yii::$app->user->id;
- $orderQuery = BaDecOrder::find()
- ->alias('DO')
- ->where($condition, $params)
- ->select('DO.DEC_SN,DO.ORDER_SN,DO.CREATED_AT,O.STATUS,O.CONSIGNEE,O.MOBILE,O.PAY_TYPE,O.PAY_AT,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,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')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', BaOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- // 订单中间表只查询待支付和支付失败的订单
- $params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value']; // 待支付
- $params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value']; // 支付失败
- $orderStandardQuery = BaApproachDecOrder::find()
- ->alias('DO')
- ->where($condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $params)
- ->select('DO.DEC_SN,DO.ORDER_SN,DO.CREATED_AT,O.STATUS,O.CONSIGNEE,O.MOBILE,O.PAY_TYPE,O.PAY_AT,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,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')
- ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'DO.TO_USER_ID=U.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS RU', 'DO.REC_USER_ID=RU.ID')
- ->join('LEFT JOIN', User::tableName() . ' AS CU', 'DO.CON_USER_ID=CU.ID')
- ->join('LEFT JOIN', BaApproachOrder::tableName() . ' AS O', 'O.SN=DO.ORDER_SN')
- ->orderBy('DO.CREATED_AT DESC');
- $queryAll = $orderQuery->union($orderStandardQuery, true);
- $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
- $totalCount = $query->count();
- $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
- $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();
- $data = [
- 'list' => $lists,
- 'currentPage'=>$pagination->page,
- 'totalPages'=>$pagination->pageCount,
- 'startNum' => $pagination->page * $pagination->pageSize + 1,
- 'totalCount' => $pagination->totalCount,
- 'pageSize' => $pagination->pageSize,
- ];
- foreach ($data['list'] as &$value) {
- if (($value['PAY_TYPE'] == 'pay_stack') && in_array($value['STATUS'], [\Yii::$app->params['orderStatus']['notPaid']['value'], \Yii::$app->params['orderStatus']['failPaid']['value']])) {
- // 订单中间表
- $orderGoods = BaApproachOrderGoods::findAllAsArray('ORDER_SN=:ORDER_SN', [':ORDER_SN' => $value['ORDER_SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- } else {
- // 订单表
- $orderGoods = BaOrderGoods::findAllAsArray('ORDER_SN=:ORDER_SN', [':ORDER_SN' => $value['ORDER_SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
- }
- $value['hasChildren'] = $orderGoods;
- $value['STATUS'] = \Yii::$app->params['orderStatus'][$value['STATUS']]['label'] ?? '';
- $value['CREATED_AT'] = $value['CREATED_AT'] ? Date::convert($value['CREATED_AT'],'Y-m-d H:i:s') : '';
- $value['PAY_TYPE'] = array_column(ShopGoods::getSaleType(), NULL, 'label')[$value['PAY_TYPE']]['name'] ?? '';
- $value['FULL_ADDRESS'] = trim(implode(', ', [$value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], Region::getCnName($value['PROVINCE'])]), ', ');
- unset($value['ADDRESS'], $value['CITY_NAME'], $value['LGA_NAME'], $value['PROVINCE']);
- }
- return $data;
- }
- /**
- * 导出订单.
- * @return mixed
- * @throws HttpException
- */
- public function actionBaDecOrderExport()
- {
- $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 = BaDecOrder::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' => BaDecOrder::tableName() . ' AS DO',
- 'join' => [
- ['LEFT JOIN', BaUser::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', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN'],
- ['LEFT JOIN', BaOrder::tableName() . ' AS OD', 'OD.SN=DO.ORDER_SN'],
- ],
- ]);
- if (!$data['list']) {
- $data = BaApproachDecOrder::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' => BaApproachDecOrder::tableName() . ' AS DO',
- 'join' => [
- ['LEFT JOIN', BaUser::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', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=DO.ORDER_SN'],
- ['LEFT JOIN', BaApproachOrder::tableName() . ' AS OD', 'OD.SN=DO.ORDER_SN'],
- ],
- ]);
- }
- $userId = '';
- $userName = '';
- $address = '';
- $mobile = '';
- $orderAt = '';
- $orderDetails = '';
- $orderAmount = 0; // 合计总额
- $orderNums = 0; // 合计总数
- $totalTaxAmount = 0; // 合计税额
- $totalAmount = 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['CREATED_AT'],'Y-m-d H:i:s');
- // 总价
- $totalAmount = $value['BUY_NUMS'] * $value['REAL_PRICE'];
- $orderAmount += $totalAmount;
- $orderNums += $value['BUY_NUMS'];
- // 税额
- $taxAmount = floatval(Tool::formatPrice(($value['REAL_PRICE'] - ($value['REAL_PRICE'] / (1 + $value['TAX_RATE'] / 100))) * $value['BUY_NUMS']));
- $totalTaxAmount += $taxAmount;
- $taxAmount = sprintf('%.2f', $taxAmount);
- $totalAmount = sprintf('%.2f', $totalAmount);
- // 订单详情
- $orderDetails .= <<<EOT
- <tr>
- <td style="text-align: center;">{$value['SKU_CODE']}</td>
- <td style="text-align: center;">{$value['GOODS_TITLE']}</td>
- <td style="text-align: right;">{$value['REAL_PRICE']}</td>
- <td style="text-align: right;">{$value['BUY_NUMS']}</td>
- <td style="text-align: right;">{$value['TAX_RATE']}%</td>
- <td style="text-align: right;">{$taxAmount}</td>
- <td style="text-align: right;">{$totalAmount}</td>
- </tr>
- EOT;
- }
- $memberCode = Yii::t('app', 'memberCode');
- $memberName = Yii::t('app', 'memberName');
- $memberAddress = Yii::t('app', 'memberAddress');
- $memberPhone = Yii::t('app', 'memberPhone');
- $orderCode = Yii::t('app', 'orderCode');
- $orderDetail = Yii::t('app', 'orderDetail');
- $productCode = Yii::t('app', 'productCode');
- $productName = Yii::t('app', 'productName');
- $productPrice = Yii::t('app', 'productPrice');
- $quantity = Yii::t('app', 'qty');
- $taxRate = Yii::t('app', 'taxRate');
- $totalTax = Yii::t('app', 'totalTax');
- $totalAmount = Yii::t('app', 'totalAmount');
- $total = Yii::t('app', 'total');
- $signature = Yii::t('app', 'signature');
- $date = Yii::t('app', 'date');
- $createAt = Yii::t('app', 'createAt');
- // 订单基本信息
- $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;">{$memberCode}</td>
- <td width="70%">{$userId}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberName}</td>
- <td width="70%">{$userName}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberAddress}</td>
- <td width="70%">{$address}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberPhone}</td>
- <td width="70%">{$mobile}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$orderCode}</td>
- <td width="70%">{$orderSn}</td>
- </tr>
- <tr>
- <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$createAt}</td>
- <td width="70%">{$orderAt}</td>
- </tr>
- <tr>
- <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">{$orderDetail}</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'] = '页面';
- $orderAmount = sprintf('%.2f', $orderAmount);
- $totalTaxAmount = sprintf('%.2f', $totalTaxAmount);
- $context = <<<ORDER
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>{$orderDetail}</title>
- <style>
- table {
- border-collapse: collapse;
- }
- table td, table th {
- border: 1px solid #ccc;
- /*padding: 5px 5px;*/
- 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>{$orderDetail}</b><br></p>
- <div>
- <div style="display: block; width: 100%;">
- {$orderBase}
-
- <table border="1" width="100%" style="padding: 10px 5px; text-align: center;">
- <tr>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productCode}</th>
- <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productName}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productPrice}</th>
- <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">{$quantity}</th>
- <th width="12%" style="font-size: 14px; font-weight: bold; text-align: center;">{$taxRate}</th>
- <th width="13%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalTax}</th>
- <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalAmount}</th>
- </tr>
- {$orderDetails}
- <tr>
- <td colspan="3">{$total}</td>
- <td style="text-align: right;">{$orderNums}</td>
- <td></td>
- <td style="text-align: right;">{$totalTaxAmount}</td>
- <td style="text-align: right;">{$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;">{$signature}:</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;">{$date}:</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', '0', '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);
- // $image_file = \Yii::$app->basePath . '/../frontendEle/src/static/img/ngds-logo.jpg';
- // if (!file_exists($image_file)) {
- // $image_file = \Yii::$app->runtimePath . '/../common/uploads/ngds-logo.jpg';
- // }
- $image_file = \Yii::$app->runtimePath . '/../ngds-logo.jpg';
- $image = file_get_contents($image_file);
- $pdf->Image('@' . $image, 15, 12, 20, 7, 'JPG');
- $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]);
- }
- /**
- * AMP
- */
- public function actionAutoMaintenance()
- {
- // 会员信息
- $user = User::findOneAsArray('ID=:ID', [':ID' => \Yii::$app->request->get('userId')]);
- if (!$user) {
- return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
- }
- $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0 OR FIND_IN_SET(4,GIFT_TYPE)>0) AND N.COUNTRY_ID=:COUNTRY_ID AND AUTO_MAINTENANCE=1';
- $data = ShopGoods::lists($condition, [':COUNTRY_ID' => $user['COUNTRY_ID']], [
- 'select' => 'S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID',
- 'from' => ShopGoods::tableName() . ' AS S',
- 'join' => [
- ['INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID = S.ID'],
- ],
- 'orderBy' => 'SORT ASC,CREATED_AT DESC',
- 'limit' => 100,
- ]);
- $currencies = Currency::getAllData();
- $currencies = array_column($currencies, NULL, 'ID');
- foreach ($data['list'] as $key => $value) {
- $data['list'][$key]['DISCOUNT'] = in_array($value['TYPE'], [1, 2]) ? ShopGoods::getGoodType()[$value['TYPE']]['discount'] : $value['SELL_DISCOUNT'] * 100;
- $data['list'][$key]['COIN'] = $currencies[$value['LOCAL_CURRENCY_ID']]['CODE'] ?? '';
- }
- return static::notice($data);
- }
- /**
- * AMP
- */
- public function actionAutoMaintenanceSureOrder()
- {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderForm();
- $formModel->scenario = 'autoMaintenanceOrder';
- $formModel->remark = Yii::t('app', 'autoMaintenance');
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $stockist = $post['decUserName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- try {
- if ($formModel->load($post, '') && $formModel->autoMaintenanceSureOrder()) {
- return static::notice(Yii::t('app', 'successfully'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } catch (HttpException|Exception|\Throwable $e) {
- return static::notice(Form::formatErrorsForApi($e->getMessage()), 400);
- }
- }
- }
- /**
- * AMP
- */
- public function actionAutoMaintenanceApproachSureOrder(){
- if (\Yii::$app->request->isPost) {
- $formModel = new ApproachAutoMaintenanceOrderForm();
- $formModel->scenario = 'autoMaintenanceOrder';
- $formModel->remark = 'Auto Maintenance Order';
- $post = \Yii::$app->request->post();
- $post['type'] = DeclarationForm::TYPE_FX;
- $stockist = $post['decUserName'] ?? '';
- if (!$stockist) {
- return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
- }
- try {
- if ($formModel->load($post, '') && $order = $formModel->autoMaintenanceSureOrder()) {
- return static::notice($order);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } catch (\yii\db\Exception|HttpException|Exception $e) {
- return static::notice(Form::formatErrorsForApi($e->getMessage()), 400);
- }
- }
- }
- }
|