<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Faka\Admin\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Str; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminConfigBuilder; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\Response; use ModStart\Core\Util\CRUDUtil; use ModStart\Form\Form; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasFields; use Module\Faka\Type\ProductStockStatus; class ProductStockController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $A2Tuf) { $A2Tuf->init('faka_product_stock')->field(function ($A2Tuf) { $A2Tuf->select('productId', '产品')->optionModel('faka_product', 'id', 'title'); $A2Tuf->type('status', '状态')->type(ProductStockStatus::class); $A2Tuf->text('no', modstart_config('Faka_FieldNameNo', '卡号')); $A2Tuf->text('secret', modstart_config('Faka_FieleNameSecret', '卡密')); $A2Tuf->text('expire', modstart_config('Faka_FieldNameExpire', '过期时间')); })->gridFilter(function (GridFilter $cbHm3) { $cbHm3->like('no', modstart_config('Faka_FieldNameNo', '卡号')); $cbHm3->eq('productId', '产品')->selectModel('faka_product', 'id', 'title'); $cbHm3->eq('status', '状态')->radio(ProductStockStatus::class); })->title('商品卡券')->canShow(false); } public function add(AdminConfigBuilder $A2Tuf) { goto WTyGU; WTyGU: $A2Tuf->useDialog(); goto leqTC; GR2sn: $A2Tuf->textarea('codes', '卡券')->rules('required')->help('<p>卡券可以是以下三种格式，每行一个，一次最多导入1000个。</p>
                        <p>----------------------------</p>
                        <p><b>' . modstart_config('Faka_FieldNameNo', '卡号') . ',' . modstart_config('Faka_FieleNameSecret', '卡密') . ',' . modstart_config('Faka_FieldNameExpire', '过期时间') . '</b></p>
                        <p><b>' . modstart_config('Faka_FieldNameNo', '卡号') . ',' . modstart_config('Faka_FieleNameSecret', '卡密') . '</b></p>
                        <p><b>' . modstart_config('Faka_FieldNameNo', '卡号') . '</b></p>
                        <p>----------------------------</p>
                        '); goto jAa6o; leqTC: $A2Tuf->pageTitle('导入卡券'); goto jvwGP; jAa6o: return $A2Tuf->perform(null, function (Form $OkcU0) { $smBDO = $OkcU0->dataForming(); $OPVbm = $smBDO['productId']; $kPKEq = $smBDO['codes']; if (empty($kPKEq)) { return Response::generateError('卡券不能为空'); } $yCYNK = explode('
', $kPKEq); $kPKEq = array(); foreach ($yCYNK as $Ddavd => $eNUnj) { goto O3JA0; O202A: $eNUnj = str_replace('，', ',', $eNUnj); goto SIVgS; UG2t8: $vPOhn['orderId'] = 0; goto Nt9gf; SbL9g: $vPOhn = array(); goto OTn04; OTn04: switch (count($nzUKg)) { case 1: goto Oduqa; xB9Yt: $vPOhn['expire'] = ''; goto oitsK; oitsK: break; goto Ysq8m; tqzEQ: $vPOhn['secret'] = ''; goto xB9Yt; Oduqa: $vPOhn['no'] = trim($nzUKg[0]); goto tqzEQ; Ysq8m: case 2: goto e01QQ; jPprS: $vPOhn['secret'] = trim($nzUKg[1]); goto jDPGY; UcEK9: break; goto wAuV2; jDPGY: $vPOhn['expire'] = ''; goto UcEK9; e01QQ: $vPOhn['no'] = trim($nzUKg[0]); goto jPprS; wAuV2: case 3: goto ipaAa; W25o0: break; goto KRDAa; ipaAa: $vPOhn['no'] = trim($nzUKg[0]); goto Mx__d; Mx__d: $vPOhn['secret'] = trim($nzUKg[1]); goto HRObP; HRObP: $vPOhn['expire'] = trim($nzUKg[2]); goto W25o0; KRDAa: } goto JCOT0; Nt9gf: $vPOhn['status'] = ProductStockStatus::NOT_USED; goto i4QF6; SIVgS: $nzUKg = explode(',', $eNUnj); goto SbL9g; BSPND: $vPOhn['productId'] = $OPVbm; goto UG2t8; O3JA0: $eNUnj = trim($eNUnj); goto V4xC6; V4xC6: if (empty($eNUnj)) { continue; } goto O202A; i4QF6: $kPKEq[] = $vPOhn; goto L0_Nv; JCOT0: if (empty($vPOhn)) { return Response::generateError('第' . ($Ddavd + 1) . '行数据格式不正确'); } goto BSPND; L0_Nv: } if (count($kPKEq) > 1000) { return Response::generateError('一次最多导入1000个'); } try { ModelUtil::insertAll('faka_product_stock', $kPKEq); } catch (\Exception $hSVcc) { if (Str::contains($hSVcc->getMessage(), 'Duplicate entry')) { return Response::generateError('包含重复的' . modstart_config('Faka_FieldNameNo', '卡号')); } throw $hSVcc; } return Response::generate(0, '成功导入' . count($kPKEq) . '个卡券', null, CRUDUtil::jsDialogCloseAndParentGridRefresh()); }); goto M028l; jvwGP: $A2Tuf->select('productId', '产品')->optionModel('faka_product', 'id', 'title')->required(); goto GR2sn; M028l: } }