|
|
@@ -12,6 +12,7 @@ use common\helpers\Cache;
|
|
|
use common\helpers\Date;
|
|
|
use common\helpers\Form;
|
|
|
use common\helpers\LoggerTool;
|
|
|
+use common\helpers\PayStack;
|
|
|
use common\helpers\Tool;
|
|
|
use common\helpers\user\Info;
|
|
|
use common\models\ApproachDecOrder;
|
|
|
@@ -46,6 +47,7 @@ use common\models\ShopGoodsNature;
|
|
|
use common\models\User;
|
|
|
use common\models\UserBonus;
|
|
|
use common\models\UserPerformance;
|
|
|
+use common\services\GuestDeclarationOrderService;
|
|
|
use common\models\UserWallet;
|
|
|
use Yii;
|
|
|
use yii\base\Exception;
|
|
|
@@ -203,6 +205,57 @@ class ShopController extends BaseController {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 无需登录的购物车订单展示
|
|
|
+ * @throws HttpException
|
|
|
+ */
|
|
|
+ public function actionNoLoginShowCart(){
|
|
|
+ $countryId = Yii::$app->request->get('countryId');
|
|
|
+ if (!filter_var($countryId, FILTER_VALIDATE_INT) || $countryId <= 0) {
|
|
|
+ return static::notice('countryId is required', 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = User::find()
|
|
|
+ ->select('ID,COUNTRY_ID')
|
|
|
+ ->where(['COUNTRY_ID' => $countryId, 'IS_DEC' => 1])
|
|
|
+ ->orderBy(['USER_NAME' => SORT_ASC])
|
|
|
+ ->asArray()
|
|
|
+ ->one();
|
|
|
+ if (!$user) {
|
|
|
+ return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $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']);
|
|
|
+ $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
|
|
|
+
|
|
|
+ $freeTemplate = FreeTemplate::getByCountryId($user['COUNTRY_ID']);
|
|
|
+ $sysConfig = Cache::getSystemConfig();
|
|
|
+
|
|
|
+ return static::notice([
|
|
|
+ 'payList' => ShopGoods::payTypesNoLogin(),
|
|
|
+ 'allAddress' => $allAddress,
|
|
|
+ 'sellType' => ShopGoods::getCategoryTypeNoLogin(),
|
|
|
+ 'freight' => 0,
|
|
|
+ 'freeShipping' => 0,
|
|
|
+ 'isDec' => 1,
|
|
|
+ 'coin' => 'NGN',
|
|
|
+ 'ampDivideLine' => (float)($sysConfig['ampBVCondition']['VALUE'] ?? 0),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 确认订单
|
|
|
*/
|
|
|
@@ -324,55 +377,75 @@ class ShopController extends BaseController {
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
public function actionVerifyApproachOrder() {
|
|
|
+ LoggerTool::error('actionVerifyApproachOrder in: ');
|
|
|
if (\Yii::$app->request->isPost) {
|
|
|
- $request = \Yii::$app->request->post();
|
|
|
-
|
|
|
- LoggerTool::notice($request);
|
|
|
+ $rawBody = \Yii::$app->request->getRawBody();
|
|
|
+ LoggerTool::error('actionVerifyApproachOrder in: '.$rawBody);
|
|
|
+ $signature = (string) \Yii::$app->request->headers->get('x-paystack-signature', '');
|
|
|
+ if (!PayStack::verifyWebhookSignature($rawBody, $signature, PayStack::getSecretKey())) {
|
|
|
+ return http_response_code(401);
|
|
|
+ }
|
|
|
+ $request = json_decode($rawBody, true);
|
|
|
+ if (!is_array($request) || empty($request['data']) || empty($request['data']['reference'])) {
|
|
|
+ return http_response_code(400);
|
|
|
+ }
|
|
|
|
|
|
// 支付webhook回调日志
|
|
|
Tool::approachOrderCall($request);
|
|
|
|
|
|
try {
|
|
|
- $data = $request['data'];
|
|
|
- $status = $request['data']['status'] ?? 'false';
|
|
|
+ $webhookData = $request['data'];
|
|
|
+ $verified = PayStack::transactionVerify((string) $webhookData['reference']);
|
|
|
+ if (empty($verified['status']) || empty($verified['data']) || !is_array($verified['data'])) {
|
|
|
+ LoggerTool::error('PayStack transaction verification failed for reference ' . $webhookData['reference']);
|
|
|
+ return http_response_code(500);
|
|
|
+ }
|
|
|
+ $data = $verified['data'];
|
|
|
+ $status = $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'] ?? '';
|
|
|
+ $orderSn = $customFields[0]['value'] ?? '';
|
|
|
$orderType = $customFields[1]['value'] ?? false;
|
|
|
+ if ($orderType === 'guestUserDec') {
|
|
|
+ if ($status !== 'success') {
|
|
|
+ (new GuestDeclarationOrderService())->markPaymentFailed((string) $data['reference'], $data);
|
|
|
+ return http_response_code(200);
|
|
|
+ }
|
|
|
+ (new GuestDeclarationOrderService())->completePaidDraft($orderSn, $data);
|
|
|
+ return http_response_code(200);
|
|
|
+ }
|
|
|
+
|
|
|
$formModel = new ApproachOrderForm();
|
|
|
$formModel->scenario = 'verifyPayStack';
|
|
|
$load = [
|
|
|
- 'sn' => $oderSn,
|
|
|
+ 'sn' => $orderSn,
|
|
|
'scenario' => 'verifyPayStack',
|
|
|
'status' => $orderStatus,
|
|
|
'note' => [
|
|
|
- 'id' => $data['id'],
|
|
|
- 'domain' => $data['domain'],
|
|
|
- 'status' => $data['status'],
|
|
|
+ 'id' => $data['id'] ?? null,
|
|
|
+ 'domain' => $data['domain'] ?? null,
|
|
|
+ 'status' => $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'],
|
|
|
+ 'amount' => $data['amount'] ?? null,
|
|
|
+ 'created_at' => $data['created_at'] ?? null,
|
|
|
+ 'paid_at' => $data['paid_at'] ?? null,
|
|
|
+ 'channel' => $data['channel'] ?? null,
|
|
|
+ 'currency' => $data['currency'] ?? null,
|
|
|
+ 'metadata' => $data['metadata'] ?? [],
|
|
|
'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()));
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ LoggerTool::error('actionVerifyApproachOrder failed: ' . get_class($e));
|
|
|
return http_response_code(500);
|
|
|
}
|
|
|
}
|
|
|
@@ -536,6 +609,59 @@ class ShopController extends BaseController {
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 无需登录查看最小编号报单中心账号的订单详情
|
|
|
+ */
|
|
|
+ public function actionNoLoginOrderDetail()
|
|
|
+ {
|
|
|
+ $orderSn = Yii::$app->request->get('orderSn');
|
|
|
+ if (!is_scalar($orderSn) || trim((string)$orderSn) === '') {
|
|
|
+ return static::notice('orderSn is required', 400);
|
|
|
+ }
|
|
|
+ $orderSn = trim((string)$orderSn);
|
|
|
+
|
|
|
+ $order = Order::find()
|
|
|
+ ->alias('O')
|
|
|
+ ->select('O.ID,O.SN,O.USER_ID,O.USER_NAME,O.ORDER_TYPE,O.ORDER_AMOUNT,O.PV,O.PAY_AMOUNT,O.PAY_PV,O.STATUS,O.CREATED_AT,O.PAY_TYPE,O.PAY_AT,O.CONSIGNEE,O.MOBILE,O.TEL,O.ADDRESS,O.CITY_NAME,O.LGA_NAME,O.PROVINCE,O.COUNTRY_ID,O.CURRENCY_ID,O.FREIGHT,O.PAY_FREIGHT,O.DELIVERY_STATUS,O.DELIVERY_PERIOD,O.DELIVERY_AT,O.EXPRESS_COMPANY,O.ORDER_TRACK_NO,O.EXPRESS_TYPE,O.FRONT_REMARK,O.PERIOD_NUM,O.WAREHOUSE,O.EMAIL,O.AUTO_MAINTENANCE,O.INVOICE_REMARK,U.REAL_NAME,C.CODE AS CURRENCY')
|
|
|
+ ->leftJoin(User::tableName() . ' U', 'U.ID=O.USER_ID')
|
|
|
+ ->leftJoin(Currency::tableName() . ' C', 'C.ID=O.CURRENCY_ID')
|
|
|
+ ->where(['O.SN' => $orderSn, 'O.IS_DELETE' => 0])
|
|
|
+ ->asArray()
|
|
|
+ ->one();
|
|
|
+
|
|
|
+ if (!$order) {
|
|
|
+ return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
|
|
|
+ }
|
|
|
+
|
|
|
+// $stockist = User::find()
|
|
|
+// ->select('ID')
|
|
|
+// ->where(['COUNTRY_ID' => $order['COUNTRY_ID'], 'IS_DEC' => 1])
|
|
|
+// ->orderBy(['USER_NAME' => SORT_ASC])
|
|
|
+// ->asArray()
|
|
|
+// ->one();
|
|
|
+// if (!$stockist || $order['USER_ID'] != $stockist['ID']) {
|
|
|
+// return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
|
|
|
+// }
|
|
|
+
|
|
|
+ $goods = OrderGoods::find()
|
|
|
+ ->alias('OG')
|
|
|
+ ->select(['OG.SKU_CODE', 'OG.GOODS_TITLE', 'OG.BUY_NUMS', 'OG.TAX_RATE', 'OG.REAL_PV', 'OG.REAL_PRICE', 'SG.COVER'])
|
|
|
+ ->leftJoin(ShopGoods::tableName() . ' SG', 'SG.ID = OG.GOODS_ID')
|
|
|
+ ->where(['OG.ORDER_SN' => $orderSn])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+
|
|
|
+ $payType = $order['PAY_TYPE'];
|
|
|
+ $order['ORDER_TYPE'] = $order['ORDER_TYPE'] == 'ZC' ? 'Welcome Pack' : (in_array($payType, ['cash', 'pay_stack']) ? 'Repeat Purchase' : 'Points');
|
|
|
+ $order['PAY_TYPE'] = array_column(ShopGoods::SALE_TYPE, null, 'label')[$order['PAY_TYPE']]['name'] ?? '';
|
|
|
+ $order['STATUS'] = Yii::$app->params['orderStatus'][$order['STATUS']]['label'] ?? '';
|
|
|
+ $order['FULL_ADDRESS'] = trim(implode(', ', [$order['ADDRESS'], $order['CITY_NAME'], $order['LGA_NAME'], Region::getCnName($order['PROVINCE'])]), ', ');
|
|
|
+ $order['SHOW_BV'] = !in_array($payType, [5, 6]);
|
|
|
+ $order['COUNTRY'] = Countries::getById($order['COUNTRY_ID'])['NAME'] ?? '';
|
|
|
+
|
|
|
+ return static::notice(['order' => $order, 'goods' => $goods]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 我的订单.(自己复消+自己加入时的首单)
|
|
|
* 创建人是自己+USER_ID是自己的复消单、创建人不是自己+USER_ID是自己的报单
|
|
|
@@ -581,10 +707,22 @@ class ShopController extends BaseController {
|
|
|
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');
|
|
|
+ $orderGoods = ApproachOrderGoods::find()
|
|
|
+ ->alias('OG')
|
|
|
+ ->select(['OG.SKU_CODE', 'OG.GOODS_TITLE', 'OG.BUY_NUMS', 'OG.TAX_RATE', 'OG.REAL_PV', 'OG.REAL_PRICE', 'SG.COVER'])
|
|
|
+ ->leftJoin(ShopGoods::tableName() . ' SG', 'SG.ID = OG.GOODS_ID')
|
|
|
+ ->where(['OG.ORDER_SN' => $value['SN']])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
} else {
|
|
|
// 订单表
|
|
|
- $orderGoods = OrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
|
|
|
+ $orderGoods = OrderGoods::find()
|
|
|
+ ->alias('OG')
|
|
|
+ ->select(['OG.SKU_CODE', 'OG.GOODS_TITLE', 'OG.BUY_NUMS', 'OG.TAX_RATE', 'OG.REAL_PV', 'OG.REAL_PRICE', 'SG.COVER'])
|
|
|
+ ->leftJoin(ShopGoods::tableName() . ' SG', 'SG.ID = OG.GOODS_ID')
|
|
|
+ ->where(['OG.ORDER_SN' => $value['SN']])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
}
|
|
|
$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');
|
|
|
@@ -647,10 +785,22 @@ class ShopController extends BaseController {
|
|
|
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');
|
|
|
+ $orderGoods = ApproachOrderGoods::find()
|
|
|
+ ->alias('OG')
|
|
|
+ ->select(['OG.SKU_CODE', 'OG.GOODS_TITLE', 'OG.BUY_NUMS', 'OG.TAX_RATE', 'OG.REAL_PV', 'OG.REAL_PRICE', 'SG.COVER'])
|
|
|
+ ->leftJoin(ShopGoods::tableName() . ' SG', 'SG.ID = OG.GOODS_ID')
|
|
|
+ ->where(['OG.ORDER_SN' => $value['SN']])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
} else {
|
|
|
// 订单表
|
|
|
- $orderGoods = OrderGoods::findAllAsArray('ORDER_SN=:SN', [':SN' => $value['SN']], 'SKU_CODE,GOODS_TITLE,BUY_NUMS,TAX_RATE,REAL_PV,REAL_PRICE');
|
|
|
+ $orderGoods = OrderGoods::find()
|
|
|
+ ->alias('OG')
|
|
|
+ ->select(['OG.SKU_CODE', 'OG.GOODS_TITLE', 'OG.BUY_NUMS', 'OG.TAX_RATE', 'OG.REAL_PV', 'OG.REAL_PRICE', 'SG.COVER'])
|
|
|
+ ->leftJoin(ShopGoods::tableName() . ' SG', 'SG.ID = OG.GOODS_ID')
|
|
|
+ ->where(['OG.ORDER_SN' => $value['SN']])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
}
|
|
|
$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');
|
|
|
@@ -699,6 +849,66 @@ class ShopController extends BaseController {
|
|
|
return static::notice($data);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据国家获取最小编号的报单中心账号(无需登录)
|
|
|
+ */
|
|
|
+ public function actionNoLoginReconsume() {
|
|
|
+ $countryId = Yii::$app->request->get('countryId');
|
|
|
+ if (!filter_var($countryId, FILTER_VALIDATE_INT) || $countryId <= 0) {
|
|
|
+ return static::notice('countryId is required', 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $user_one = User::find()
|
|
|
+ ->select('ID,USER_NAME')
|
|
|
+ ->where(['COUNTRY_ID' => $countryId, 'IS_DEC' => 1])
|
|
|
+ ->orderBy(['USER_NAME' => SORT_ASC])
|
|
|
+ ->asArray()
|
|
|
+ ->one();
|
|
|
+
|
|
|
+ if (!$user_one) {
|
|
|
+ return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
|
|
|
+ }
|
|
|
+// var_dump($user_one['ID']);die();
|
|
|
+
|
|
|
+ // 会员信息
|
|
|
+ $user = User::findOneAsArray('ID=:ID', [':ID' => $user_one['ID']]);
|
|
|
+ if (!$user) {
|
|
|
+ return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
|
|
|
+ }
|
|
|
+
|
|
|
+// $condition = ' AND S.STATUS=1 AND S.CATEGORY_TYPE=1 AND FIND_IN_SET(1,S.GIFT_TYPE)>0 AND (S.INSTALMENT=0 OR S.INSTALMENT=1) 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,
|
|
|
+// ]);
|
|
|
+
|
|
|
+ $condition = ' AND STATUS=1 AND (FIND_IN_SET(2,GIFT_TYPE)>0 OR FIND_IN_SET(4,GIFT_TYPE)>0) AND S.INSTALMENT=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
|
|
|
@@ -766,6 +976,43 @@ class ShopController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 无需登录的复消确认订单
|
|
|
+ */
|
|
|
+ public function actionNoLoginReconsumeSureOrder(){
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $countryId = $post['countryId'] ?? null;
|
|
|
+ if (!filter_var($countryId, FILTER_VALIDATE_INT) || $countryId <= 0) {
|
|
|
+ return static::notice('countryId is required', 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = User::find()
|
|
|
+ ->select('ID,USER_NAME')
|
|
|
+ ->where(['COUNTRY_ID' => $countryId, 'IS_DEC' => 1])
|
|
|
+ ->orderBy(['USER_NAME' => SORT_ASC])
|
|
|
+ ->asArray()
|
|
|
+ ->one();
|
|
|
+ if (!$user) {
|
|
|
+ return static::notice(Yii::t('app', 'stockistDoesNotExist'), 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $formModel = new ApproachReconsumeOrderForm();
|
|
|
+ $formModel->scenario = 'noLoginReconsumeOrder';
|
|
|
+ $formModel->remark = Yii::t('app', 'reconsume');
|
|
|
+ $formModel->noLoginUserId = $user['ID'];
|
|
|
+ $post['type'] = DeclarationForm::TYPE_FX;
|
|
|
+ $post['payType'] = 'pay_stack';
|
|
|
+ if ($formModel->load($post, '')) {
|
|
|
+ $formModel->userName = $user['USER_NAME'];
|
|
|
+ $formModel->decUserName = $user['USER_NAME'];
|
|
|
+ if ($order = $formModel->add()) {
|
|
|
+ return static::notice($order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 商品列表tabs分类
|
|
|
* @return mixed
|
|
|
@@ -806,7 +1053,6 @@ class ShopController extends BaseController {
|
|
|
*/
|
|
|
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";
|
|
|
@@ -1065,6 +1311,272 @@ ORDER;
|
|
|
return static::notice(['fileUrl' => $path, 'targetName' => $file_name]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 无需登录导出订单.
|
|
|
+ * @return mixed
|
|
|
+ * @throws HttpException
|
|
|
+ * @throws \Mpdf\MpdfException
|
|
|
+ */
|
|
|
+ public function actionNoLoginOrderExport()
|
|
|
+ {
|
|
|
+ $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['CONSIGNEE'];
|
|
|
+ $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%"></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->basePath . '/../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
|
|
|
@@ -1999,3 +2511,5 @@ ORDER;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|