<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Faka\Api\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Cookie; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Response; use ModStart\Core\Util\RandomUtil; use Module\Faka\Constant\FakaConstant; use Module\Faka\Type\ProductOrderProcessStatus; use Module\Faka\Type\ProductOrderStatus; use Module\PayCenter\Support\PayCenterPerform; class ProductController extends Controller { public function all() { goto DhdoS; ci6oz: $PeGDD = ModelUtil::all('faka_product', array(), array('*'), array('id', 'desc')); goto G_wzI; Z0ud8: return Response::generateSuccessData(array('categories' => $FLByG, 'products' => $PeGDD)); goto M6xD2; G_wzI: ModelUtil::decodeRecordsJson($PeGDD, array('customField1', 'customField2', 'customField3', 'customField4', 'customField5')); goto Z0ud8; DhdoS: $FLByG = ModelUtil::all('faka_product_category', array(), array('*'), array('sort', 'asc')); goto ci6oz; M6xD2: } public function get() { goto PzIcZ; k5dPf: ModelUtil::decodeRecordJson($Wmda_, array('customField1', 'customField2', 'customField3', 'customField4', 'customField5')); goto JDp9n; aap9v: BizException::throwsIfEmpty('商品不存在', $Wmda_); goto k5dPf; ADb0y: $Wmda_ = ModelUtil::get('faka_product', $pNLgg); goto aap9v; S1xCf: $pNLgg = $Ylazq->getInteger('id'); goto ADb0y; JDp9n: return Response::generateSuccessData(array('product' => $Wmda_)); goto XMEAP; PzIcZ: $Ylazq = InputPackage::buildFromInput(); goto S1xCf; XMEAP: } public function submit(PayCenterPerform $g7VMp) { goto sRU2q; WhXIO: $smBDO['email'] = $Ylazq->getEmail('email'); goto BHF9G; PTgfW: for ($qzlby = 1; $qzlby <= 5; $qzlby++) { if (!empty($Wmda_['customField' . $qzlby]['type'])) { if (empty($smBDO['customField' . $qzlby])) { return Response::generateError($Wmda_['customField' . $qzlby]['title'] . '为空'); } } } goto hdWLz; IHQId: BizException::throwsIf('数量填写不正确', $smBDO['amount'] < 1); goto PTgfW; hdWLz: try { goto qcuuj; OtnJ3: $smBDO['status'] = ProductOrderStatus::WAIT_PAY; goto iQE1q; Nly4x: ModelUtil::transactionCommit(); goto Iuz21; qcuuj: ModelUtil::transactionBegin(); goto u1mT4; iQE1q: $smBDO['processStatus'] = ProductOrderProcessStatus::WAIT_PROCESS; goto pbRnd; zUoBB: $smBDO['payFee'] = bcmul($Wmda_['price'], $smBDO['amount'], 2); goto FmioL; PJ8ua: $smBDO['fee'] = $Wmda_['price']; goto zUoBB; Hk5Lj: ModelUtil::update('faka_product', $Wmda_['id'], array('stock' => max($Wmda_['stock'] - $smBDO['amount'], 0))); goto OtnJ3; Rmi6D: if ($Wmda_['stock'] < $smBDO['amount']) { ModelUtil::transactionCommit(); return Response::generateError('库存不足'); } goto Hk5Lj; pbRnd: $smBDO['uid'] = $ysQ9d; goto PJ8ua; u1mT4: $Wmda_ = ModelUtil::getWithLock('faka_product', $smBDO['productId']); goto Rmi6D; FmioL: $smBDO = ModelUtil::insert('faka_product_order', $smBDO); goto Nly4x; Iuz21: return $g7VMp->performSubmitOrder(FakaConstant::PAY_ORDER, $smBDO['id'], $smBDO['payFee'], '购买：' . $Wmda_['title']); goto dlb57; dlb57: } catch (\Exception $hSVcc) { ModelUtil::transactionRollback(); return Response::generateError('购买出错:' . $hSVcc->getMessage()); } goto s9Gow; dsjXT: $smBDO = array(); goto gOaPT; BHF9G: for ($qzlby = 1; $qzlby <= 5; $qzlby++) { $smBDO['customField' . $qzlby] = $Ylazq->getTrimString('customField' . $qzlby); } goto jWMOM; ZJnX7: ModelUtil::decodeRecordJson($Wmda_, array('customField1', 'customField2', 'customField3', 'customField4', 'customField5')); goto PZJ43; gOaPT: $Ylazq = InputPackage::buildFromInput(); goto DUY12; DUY12: $smBDO['productId'] = $Ylazq->getInteger('productId'); goto wXeQ3; sRU2q: $ysQ9d = Cookie::get('uid'); goto Al2rJ; OlUyp: BizException::throwsIfEmpty('邮箱填写不正确', $smBDO['email']); goto IHQId; xz_Au: BizException::throwsIfEmpty('商品不存在', $Wmda_); goto ZJnX7; wXeQ3: $Wmda_ = ModelUtil::get('faka_product', $smBDO['productId']); goto xz_Au; Aswdz: Cookie::queue('uid', $ysQ9d, 365 * 24 * 60); goto dsjXT; jWMOM: $smBDO['remark'] = $Ylazq->getTrimString('remark'); goto OlUyp; PZJ43: $smBDO['amount'] = $Ylazq->getInteger('amount'); goto WhXIO; Al2rJ: if (empty($ysQ9d)) { $ysQ9d = RandomUtil::lowerString(64); } goto Aswdz; s9Gow: } }