| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace common\models\forms;
- use common\components\Model;
- use common\models\Order;
- use yii\base\Exception;
- class OrderInvoiceRemarkForm extends Model
- {
- public $orderSn;
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['orderSn'], 'trim'],
- [['orderSn'], 'required'],
- ['remark', 'string', 'max' => 50000],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'orderSn' => '订单号',
- 'remark' => '发票备注',
- ];
- }
- /**
- * 指定校验场景
- * @return array
- */
- public function scenarios()
- {
- $parentScenarios = parent::scenarios();
- $customScenarios = [];
- return array_merge($parentScenarios, $customScenarios);
- }
- /**
- * @throws Exception
- */
- public function remarkOrderInvoice()
- {
- if (!$this->validate()) {
- return null;
- }
- $sn = $this->orderSn;
- // 订单详情
- $orderInfo = Order::findUseDbCalc()
- ->select('ID,INVOICE_REMARK,SN,INVOICE_REMARK_EDIE_CNT,STATUS,COUNTRY_ID')
- ->where("SN=:SN", [':SN' => $sn])
- ->asArray()
- ->one();
- if (!$orderInfo) {
- throw new Exception('订单不存在');
- }
- // 已经修改过就可以再修改了
- if ($orderInfo['INVOICE_REMARK_EDIE_CNT'] > 0) {
- throw new Exception('订单已经修改过,不能再修改');
- }
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- try {
- Order::updateAll(
- ['INVOICE_REMARK' => 1, 'INVOICE_REMARK_EDIE_CNT' => 1],
- 'SN=:SN',
- ['SN' => $sn]
- );
- $transaction->commit();
- } catch(Exception $e) {
- $transaction->rollBack();
- $this->addError('add', $e->getMessage());
- return null;
- }
- return true;
- }
- }
|