| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace backendApi\modules\v1\controllers;
- use backendApi\modules\v1\models\AdminCountry;
- use backendApi\modules\v1\models\AdminRole;
- use backendApi\modules\v1\models\exportForms\BaShopExportForm;
- use backendApi\modules\v1\models\exportForms\ShopExportForm;
- use backendApi\modules\v1\models\lists\shop\DecOrderList;
- use backendApi\modules\v1\models\lists\shop\GoodsList;
- use backendApi\modules\v1\models\lists\shop\OrderDecList;
- use backendApi\modules\v1\models\lists\shop\OrderList;
- use backendApi\modules\v1\models\lists\shop\BaOrderList;
- use backendApi\modules\v1\models\lists\shop\OrderPeriodAdjustList;
- use backendApi\modules\v1\models\lists\shop\OrderShopList;
- use backendApi\modules\v1\models\lists\shop\OrderStandardList;
- use backendApi\modules\v1\models\lists\shop\PackageList;
- use backendApi\modules\v1\models\lists\shop\RemainPvList;
- use backendApi\modules\v1\models\lists\shop\FlowRemainPvList;
- use common\helpers\Cache;
- use common\helpers\Date;
- use common\helpers\Form;
- use common\helpers\LoggerTool;
- use common\models\Countries;
- use common\models\Currency;
- use common\models\CurrencyConversions;
- use common\models\DeclarationPackage;
- use common\models\DecOrder;
- use common\models\Export;
- use common\models\FlowWallet;
- use common\models\forms\DecPackageForm;
- use common\models\forms\ExcelOrderDecForm;
- use common\models\forms\ExcelOrderShopForm;
- use common\models\forms\ExcelOrderStandardForm;
- use common\models\forms\OrderDeleteForm;
- use common\models\forms\OrderForm;
- use common\models\forms\OrderInvoiceRemarkForm;
- use common\models\forms\OrderPeriodAdjustForm;
- use common\models\forms\ShopGoodsForm;
- use common\models\forms\UploadForm;
- use common\models\Order;
- use common\models\OrderPeriodAdjust;
- use common\models\Period;
- use common\models\ShopGoods;
- use common\models\ShopGoodsNature;
- use common\models\User;
- use common\models\UserInfo;
- use common\helpers\Tool;
- use Yii;
- use yii\web\HttpException;
- use yii\web\UploadedFile;
- use yii\base\Exception;
- class ShopController extends BaseController {
- public $modelClass = DecOrder::class;
- public function behaviors() {
- $behaviors = parent::behaviors();
- //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
- return $behaviors;
- }
- /**
- * 商品列表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionIndex() {
- $filter = $this->filterCondition([
- 'TYPE'=> 'TYPE',
- 'GIFT_TYPE'=> 'GIFT_TYPE',
- 'STATUS'=> 'STATUS',
- 'GOODS_NAME'=> 'GOODS_NAME',
- 'GOODS_NO'=> 'GOODS_NO',
- 'SELL_TYPE'=> 'SELL_TYPE',
- 'PRICE_PV'=> 'PRICE_PV',
- 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
- 'AUTO_MAINTENANCE' => 'AUTO_MAINTENANCE',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' ';
- $listObj = new GoodsList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 商品属性
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionGoodsNature() {
- $data = ShopGoodsNature::findAllAsArray('GOODS_ID=:GOODS_ID', [':GOODS_ID' => \Yii::$app->request->get('GOOD_ID')]);
- return static::notice($data);
- }
- /**
- * 商品列表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionGoodsListExport()
- {
- $filter = $this->filterCondition([
- 'TYPE'=> 'TYPE',
- 'GIFT_TYPE'=> 'GIFT_TYPE',
- 'STATUS'=> 'STATUS',
- 'GOODS_NAME'=> 'GOODS_NAME',
- 'GOODS_NO'=> 'GOODS_NO',
- 'SELL_TYPE'=> 'SELL_TYPE',
- 'PRICE_PV'=> 'PRICE_PV',
- 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
- 'AUTO_MAINTENANCE' => 'AUTO_MAINTENANCE',
- ]);
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopExportListName')); // 商品列表
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 添加商品
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionGoodsAdd() {
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'add';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
- return static::notice(\Yii::t('ctx', 'shopProductAddSucceededNotice'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- $countries = Cache::getCountries();
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $countries = array_filter($countries, fn($country) => in_array($country['ID'], $adminCountry));
- $countries = array_values($countries);
- }
- // 货币
- $currencies = Cache::getCurrencies();
- $currencies = array_column($currencies, NULL, 'ID');
- // 货币汇率
- $currenciesConversions = CurrencyConversions::getFromCache();
- $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
- foreach ($countries as $key => $country) {
- $countries[$key]['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
- $countries[$key]['CURRENCY_PRODUCT_RATE'] = $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0;
- }
- return static::notice([
- 'sellType' => ShopGoods::getSaleType(),
- 'goodsType' => ShopGoods::getGoodType(),
- 'giftType' => ShopGoods::getGiftType(),
- 'categoryType' => ShopGoods::getCategoryType(),
- 'countries' => $countries,
- ]);
- }
- /**
- * 编辑商品
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionGoodsEdit() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'edit';
- $formModel->id = $id;
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
- return static::notice(\Yii::t('ctx', 'shopProductEditSucceed'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
- $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
- $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
- if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
- $data['SELL_DISCOUNT'] = ShopGoods::getGoodType()[$data['TYPE']]['discount']/100;
- }
- // 国家
- $countries = Cache::getCountries();
- // 货币
- $currencies = Cache::getCurrencies();
- $currencies = array_column($currencies, NULL, 'ID');
- // 货币汇率
- $currenciesConversions = CurrencyConversions::getFromCache();
- $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $countries = array_filter($countries, fn($country) => in_array($country['ID'], $adminCountry));
- $countries = array_values($countries);
- }
- foreach ($countries as $key => $country) {
- // 货币
- $countries[$key]['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
- $countries[$key]['CURRENCY_PRODUCT_RATE'] = $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0;
- // 商品属性
- $countries[$key]['SHOP_GOODS_NATURE'] = ShopGoodsNature::findAllAsArray('GOODS_ID=:GOODS_ID AND COUNTRY_ID=:COUNTRY_ID', [':GOODS_ID' => $id, ':COUNTRY_ID' => $country['ID']]);
- }
- $data['SHOP_GOODS_NATURE'] = array_values($countries);
- return static::notice(
- [
- 'goodsInfo'=>$data,
- 'sellType' => ShopGoods::getSaleType(),
- 'goodsType' => ShopGoods::getGoodType(),
- 'giftType' => ShopGoods::getGiftType(),//ShopGoods::GIFT_TYPE,
- 'categoryType' => ShopGoods::getCategoryType(),//ShopGoods::CATEGORY_TYPE,
- ]
- );
- }
- /**
- * 上传图片
- * @return mixed
- * @throws \yii\base\Exception
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionUpload(){
- if(\Yii::$app->request->isPost){
- $formModel = new UploadForm();
- $formModel->scenario = 'goodsImg';
- $formModel->file = UploadedFile::getInstanceByName('file');
- $formModel->token = \Yii::$app->request->request('uploadToken');
- if($formModel->file && $uploader = $formModel->upload()){
- return static::notice($uploader->URL);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } else {
- $token = Cache::setUploadToken();
- return static::notice($token);
- }
- }
- /**
- * 商品上下架
- * @return mixed
- * @throws Exception
- */
- public function actionGoodsStatus() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'changeStatus';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
- return static::notice(\Yii::t('ctx', 'shopStatusSetSucceedNotice')); // 状态设置成功
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 删除商品
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionGoodsDelete(){
- $result = static::delete(ShopGoods::class);
- return $result;
- }
- /**
- * 套餐列表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionPackage() {
- $filter = $this->filterCondition([
- 'LEVEL_NAME'=> 'DP.LEVEL_ID',
- 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
- 'AMOUNT'=> 'DP.AMOUNT',
- 'PV'=> 'DP.PV',
- 'STATUS'=> 'DP.STATUS',
- 'STORE_NUMS'=>'DP.STORE_NUMS',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND DP.IS_DEL=0';
- $listObj = new PackageList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 添加报单套餐
- * @return mixed
- * @throws HttpException
- */
- public function actionPackageAdd() {
- if (\Yii::$app->request->isPost) {
- return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
- // Log::adminHandle('添加报单套餐', 1);
- });
- }
- return static::notice('非法请求', 405);
- }
- /**
- * 报单套餐获取
- * @return mixed
- * @throws HttpException
- */
- public function actionPackageGet() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
- // Log::adminHandle('编辑报单套餐', 1);
- });
- }
- $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
- return static::notice(['id' => $package['ID'],'packageName' => $package['PACKAGE_NAME'],'packageNo' => $package['PACKAGE_NO'], 'amount' => $package['AMOUNT'], 'amountPv' => $package['PV'], 'levelId' => $package['LEVEL_ID'], 'packageContent' => $package['PACKAGE_CONTENT'],'amountStandard' => $package['AMOUNT_STANDARD'],'storenums' => $package['STORE_NUMS']]);
- }
- /**
- * 套餐上下架
- * @return mixed
- * @throws Exception
- */
- public function actionPackageStatus() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new DecPackageForm();
- $formModel->scenario = 'changeStatus';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
- return static::notice('Status setting succeeded'); // 状态设置成功
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 删除套餐
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionPackageDelete(){
- $result = static::delete(DeclarationPackage::class);
- return $result;
- }
- /**
- * 报单表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionDecOrderList() {
- $filter = $this->filterCondition([
- 'DEC_SN'=> 'DO.DEC_SN',
- 'ORDER_SN'=> 'DO.ORDER_SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'TO_USER_NAME'=> 'TU.USER_NAME',
- 'REAL_NAME'=> 'TU.REAL_NAME',
- 'ID_CARD'=> 'TU.ID_CARD',
- 'MOBILE'=> 'TU.MOBILE',
- 'DEC_LV_NAME' => 'TU.DEC_LV',
- 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
- 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
- 'DEC_PV'=> 'DO.DEC_PV',
- 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
- 'REC_USER_NAME'=> 'RU.USER_NAME',
- 'CREATED_AT'=> 'DO.CREATED_AT',
- 'UPDATED_AT'=> 'DO.UPDATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND DO.IS_DEL=0';
- $listObj = new DecOrderList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 报单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionDecOrderListExport()
- {
- $filter = $this->filterCondition([
- 'DEC_SN'=> 'DO.DEC_SN',
- 'ORDER_SN'=> 'DO.ORDER_SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'TO_USER_NAME'=> 'TU.USER_NAME',
- 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
- 'DEC_PV'=> 'DO.DEC_PV',
- 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
- 'CREATED_AT'=> 'DO.CREATED_AT',
- 'UPDATED_AT'=> 'DO.UPDATED_AT',
- ]);
- $filter['condition'] .= ' AND DO.IS_DEL=0';
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopDecOrderListExport'));
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- // 删除订单
- public function actionDeleteOrder() {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderDeleteForm();
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
- return static::notice(\Yii::t('ctx', 'shopDelOrderSuccedNotice'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderInvoiceRemark() {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderInvoiceRemarkForm();
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->remarkOrderInvoice()) {
- return static::notice(\Yii::t('ctx', 'successfully'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 订单发票支付方式
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderInvoiceMethod() {
- return static::notice(['method'=>['Cash', 'Credit Card', 'Direct Banking', 'Cheque']]);
- }
- /**
- * 订单表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'ORDER_TYPE'=> 'O.ORDER_TYPE',
- 'STATUS' => 'O.STATUS',
- 'COUNTRY' => 'O.COUNTRY_ID',
- 'AUTO_MAINTENANCE' => 'O.AUTO_MAINTENANCE'
- ]);
- $condition = ' 1=1 ' . $filter['condition'];
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $quotedAdminCountry = array_map(function($item) {
- return "'" . addslashes($item) . "'";
- }, $adminCountry);
- $condition = ' 1=1 ' . $filter['condition'] . " AND O.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
- }
- $params = $filter['params'];
- $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
- $listObj = new OrderList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 订单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionOrderListExport()
- {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'ORDER_TYPE'=> 'O.ORDER_TYPE',
- 'STATUS' => 'O.STATUS',
- 'AUTO_MAINTENANCE' => 'O.AUTO_MAINTENANCE'
- ]);
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $quotedAdminCountry = array_map(function($item) {
- return "'" . addslashes($item) . "'";
- }, $adminCountry);
- $filter['condition'] = ('O.IS_DELETE=0 ' . $filter['condition']) . " AND O.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
- } else {
- $filter['condition'] = ('O.IS_DELETE=0 ' . $filter['condition']);
- }
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExport')); // 订单列表
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 外部商城订单列表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderShopList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderShopList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 外部商城报单列表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderDecList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderDecList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 分页导入excel文件到待导入数据的表中
- * @return mixed
- */
- public function actionImportOrderShopToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $orderType = \Yii::$app->request->post('orderType');
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- $excelOrderShop = new ExcelOrderShopForm();
- $excelOrderShop->checkStatus($orderDay,$orderType);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
- } catch (\Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('Error:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 导入完成标记
- * @return mixed
- * @throws HttpException
- */
- public function actionImportOrderShop() {
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $orderType = \Yii::$app->request->post('orderType');
- $excelOrderShop = new ExcelOrderShopForm();
- $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
- }
- }
- /**
- * 报单订单——分页导入excel文件到待导入数据的表中
- * @return mixed
- */
- public function actionImportOrderDecToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- $excelOrderShop = new ExcelOrderDecForm();
- $excelOrderShop->checkStatus($orderDay);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
- } catch (\Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('Error:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 报单订单导入完成标记
- * @return mixed
- * @throws HttpException
- */
- public function actionImportOrderDec() {
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $excelOrderShop = new ExcelOrderDecForm();
- $finishStatus = $excelOrderShop->finished($orderDay);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
- }
- }
- /**
- * 见习达标订单列表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionOrderStandardList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderStandardList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 分页导入excel文件到待导入数据的表中
- * @return mixed
- * @throws HttpException
- */
- public function actionImportOrderStandardToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderMonth = \Yii::$app->request->post('orderMonth');
- // $orderType = \Yii::$app->request->post('orderType');
- $orderType = 'cash';
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- //清空已经导入的表数据
- $excelOrderStandard = new ExcelOrderStandardForm();
- $excelOrderStandard->checkStatus($orderMonth);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
- } catch (Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('Error:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 达标订单导入完成标记
- * @return mixed
- * @throws HttpException
- */
- public function actionImportOrderStandard() {
- $orderMonth = \Yii::$app->request->post('orderMonth');
- $excelOrderStandard = new ExcelOrderStandardForm();
- $finishStatus = $excelOrderStandard->finished($orderMonth);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
- }
- }
- /**
- * 管理员发货
- * @return mixed
- * @throws HttpException
- */
- public function actionOrderDelivery() {
- if(\Yii::$app->request->isPost) {
- return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
- }
- return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
- }
- /**
- * 报单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionOrderListExportPdf()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
- $filter['params'] = [':SN' => $orderSn];
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- public function actionOrderInvoiceExport()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- ]);
- $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
- $filter['params'] = [':SN' => $orderSn];
- // 生成发票编号
- $order = Order::find()
- ->alias('O')
- ->select('O.*,CS.CODE AS COUNTRY_CODE')
- ->where(['SN' => $orderSn])
- ->join('LEFT JOIN', Countries::tableName() . ' AS CS', 'CS.ID=O.COUNTRY_ID')
- ->asArray()->one();
- if (!$order) {
- return static::notice('订单不存在', 400);
- }
- if (!$order['INVOICE_NO']) {
- $invoiceNo = $this->generateInvoiceNo($order['PAY_AT'],$order['COUNTRY_CODE']);
- Order::updateAll(['INVOICE_NO' => $invoiceNo], 'SN = :SN', [':SN' => $orderSn]);
- }
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'actionOrderInvoiceExport'),null,$orderSn);
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- public function actionOrderInvoiceExportFile()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- //查找最新的导出文件
- $data = Export::find()
- ->where(['REMARK' => $orderSn])
- ->orderBy(['CREATED_AT' => SORT_DESC])
- ->one();
- if (!$data || $data['IS_EXPORTING']) {
- return static::notice('导出进行中', 400);
- }
- return static::notice($data);
- }
- /**
- * 报单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionDecOrderListExportPdf()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
- $filter['params'] = [':SN' => $orderSn];
- $form = new ShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 管理员订单退款
- * @return mixed
- * @throws HttpException
- */
- public function actionOrderRefund()
- {
- if(\Yii::$app->request->isPost) {
- return parent::edit(OrderForm::class, \Yii::t('ctx', 'shopadminRefund'), 'adminRefund', ['adminRefund']);
- }
- return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
- }
- /*
- * 剩余BV页
- *
- */
- public function actionRemainPv()
- {
- $filter = $this->filterCondition([
- 'USER_NAME' => 'U.USER_NAME',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $listObj = new RemainPvList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /*
- * 剩余BV流水
- *
- */
- public function actionFlowRemainPv()
- {
- $filter = $this->filterCondition([
- 'USER_NAME' => 'U.USER_NAME',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $listObj = new FlowRemainPvList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * BA订单表
- * @return mixed
- * @throws Exception
- * @throws HttpException
- */
- public function actionBaOrderList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'ORDER_TYPE'=> 'O.ORDER_TYPE',
- 'STATUS' => 'O.STATUS',
- ]);
- $condition = ' 1=1 ' . $filter['condition'];
- $params = $filter['params'];
- $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
- $listObj = new BaOrderList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * BA订单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionBaOrderListExport()
- {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'STATUS' => 'O.STATUS',
- ]);
- $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
- $form = new BaShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopBaOrderListExport')); // 订单列表
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 报单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws HttpException
- */
- public function actionBaOrderListExportPdf()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
- $filter['params'] = [':SN' => $orderSn];
- $form = new BaShopExportForm();
- $result = $form->run($filter, \Yii::t('ctx', 'shopBrandAmbassadorOrderExport'));
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 调整订单期数
- * @return mixed
- * @throws Exception
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderPeriodAdjust()
- {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderPeriodAdjustForm();
- $formModel->scenario = 'orderPeriodAdjust';
- if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
- return static::notice(Yii::t('ctx', 'successfully'));
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } else {
- $filter = $this->filterCondition([
- 'ORDER_SN' => 'P.ORDER_SN',
- 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
- 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
- 'CREATED_AT'=> 'P.CREATED_AT',
- ]);
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $quotedAdminCountry = array_map(function($item) {
- return "'" . addslashes($item) . "'";
- }, $adminCountry);
- $filter['condition'] .= ' AND O.COUNTRY_ID IN (' . implode(',', $quotedAdminCountry) . ')';
- }
- $listObj = new OrderPeriodAdjustList();
- $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
- return static::notice($data);
- }
- }
- /**
- * 订单详情
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionOrderDetail()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
- if (!$isSuper) {
- $adminId = Yii::$app->getUser()->getUserInfo()['id'];
- $adminCountry = AdminCountry::getCountry($adminId);
- $quotedAdminCountry = array_map(function ($item) {
- return "'" . addslashes($item) . "'";
- }, $adminCountry);
- $order = Order::findOneAsArray('SN=:SN AND COUNTRY_ID IN (' . implode(',', $quotedAdminCountry) . ')', [':SN' => $orderSn]);
- } else {
- $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
- }
- if (!$order) {
- return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
- }
- $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? Yii::t('ctx', 'shopOrderListOrderTypeZc') : Yii::t('ctx', 'shopOrderListOrderTypeFx');
- $order['COUNTRY'] = Countries::getById($order['COUNTRY_ID'])['NAME'] ?? '';
- // 已挂网,不可调整
- $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
- if (!$period) {
- return static::notice(Yii::t('ctx', 'invalidPcNo'), 400);
- }
- if ($period['IS_SENT'] > 0) {
- return static::notice(Yii::t('ctx', 'orderHasBeenConnected'), 400);
- }
- // 可调整期数
- $availablePeriod = [];
- if ($order['PERIOD_NUM']) {
- $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
- foreach ($availablePeriod as $k => $item) {
- $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
- }
- }
- return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
- }
- public function actionOrderPeriodAdjustBatch()
- {
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- $orderList = [];
- $orderErr = [];
- try {
- $modernPeriod = 150; // todo: 修改后期数
- $oldPeriod = 151; // todo: 修改前期数
- foreach ($orderList as $orderSn) {
- $orderObj = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
- if (!$orderObj) {
- $orderErr[] = $orderSn;
- continue;
- }
- // 调整订单期数
- Order::updateAll(['PERIOD_NUM' => $modernPeriod], 'SN = :SN', [':SN' => $orderSn]);
- if ($orderObj['ORDER_TYPE'] === 'ZC') {
- // 调整报单期数
- DecOrder::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- // 调整会员的期数
- User::updateAll(['PERIOD_AT' => $modernPeriod], 'ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
- UserInfo::updateAll(['HIGHEST_EMP_LV_PERIOD' => $modernPeriod], 'USER_ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
- }
- // 调整流水的期数
- switch ($orderObj['PAY_TYPE']){
- case 'cash':
- FlowWallet::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- break;
- default:
- break;
- }
- // 写入调整记录
- $orderModel = new OrderPeriodAdjust();
- $orderModel->ORDER_SN = $orderSn;
- $orderModel->ORIGIN_PERIOD = $oldPeriod;
- $orderModel->MODERN_PERIOD = $modernPeriod;
- $orderModel->ADMIN_ID = 'admin';
- $orderModel->CREATED_AT = Date::nowTime();
- if (!$orderModel->save()) {
- return static::notice($orderModel->getErrors(), 400);
- }
- }
- $transaction->commit();
- } catch(\Exception $e) {
- $transaction->rollBack();
- return static::notice($e->getMessage(), 400);
- }
- return static::notice('成功. ' . json_encode($orderErr));
- }
- public function generateInvoiceNo($pay_at = '',$country_code = '')
- {
- $prefix = 'Inv'.$country_code;
- $currentDate = date('dmY',$pay_at?:time());
-
- // 查询今天生成的最新发票号(包含当天日期格式的)
- $order = Order::find()
- ->where(['STATUS' => 1, 'IS_DELETE' => 0])
- ->andWhere(['like', 'INVOICE_NO', $prefix . $currentDate])
- ->orderBy(['INVOICE_NO' => SORT_DESC])
- ->one();
- if (!$order || !$order->INVOICE_NO) {
- // 如果今天没有生成过发票号或没有符合条件的订单,从00001开始
- $no = '00001';
- } else {
- $invoiceNo = $order->INVOICE_NO;
- // 截取最后5位数字部分并+1
- $no = sprintf('%05d', intval(substr($invoiceNo, -5)) + 1);
- }
- return $prefix . $currentDate . $no;
- }
- }
|