'edit'], [['cx_mch_id'], 'required'], ]; } public function attributeLabels(){ return [ 'pay_types' => '支付类型', 'cx_mch_id' => '平台商户ID', 'share_ratio' => '积分比例%', 'orderTimeoutCancel' =>'未支付订单超时', 'orderSalesTime' =>'售后时间', 'bookEndTime' => '包厢结束提醒', ]; } public function save() { if(!$this->validate()){ return $this->getModelError(); } $t = \Yii::$app->db->beginTransaction(); $res = $this->savePayType(); if($res['code'] != 0){ $t->rollBack(); return $this->apiReturnError($res['msg']); } $key = Utils::hump2underline($this->shareRatioKey); $key = strtoupper($key); $f = Option::setOption($key, $this->shareRatio, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('积分比例%保存失败'); } $key = Utils::hump2underline($this->rechargeRemindMinuteKey); $key = strtoupper($key); $f = Option::setOption($key, $this->rechargeRemindMinute, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('充值提醒间隔保存失败'); } $key = Utils::hump2underline($this->orderTimeoutCancelKey); $key = strtoupper($key); $f = Option::setOption($key, $this->orderTimeoutCancel, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('未支付订单超时保存失败'); } $key = Utils::hump2underline($this->orderSalesTimeKey); $key = strtoupper($key); $f = Option::setOption($key, $this->orderSalesTime, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('售后时间保存失败'); } $key = Utils::hump2underline($this->bookEndTimeKey); $key = strtoupper($key); $f = Option::setOption($key, $this->bookEndTime, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('包厢结束提醒保存失败'); } if(!empty($this->storeMakeCover)){ $key = Utils::hump2underline($this->storeMakeCoverKey); $key = strtoupper($key); $f = Option::setOption($key, $this->storeMakeCover, $this->cx_mch_id); if(!$f){ $t->rollBack(); return $this->apiReturnError('包厢结束提醒保存失败'); } } $t->commit(); return $this->apiReturnSuccess('保存成功'); } private function savePayType() { PaymentTypes::updateAll(['is_open' => 0],[ 'cx_mch_id' => $this->cx_mch_id, 'is_open' => 1, ]); $pay_types_default = PaymentTypes::payTypes(); foreach ($this->pay_types as $pay_type){ $pay_type = trim($pay_type); $model = PaymentTypes::findOne(['cx_mch_id' => $this->cx_mch_id, 'short_name' => $pay_type]); if($model == null){ $model = new PaymentTypes(); $model->cx_mch_id = $this->cx_mch_id; } $model->name = $pay_types_default[$pay_type]['name']; $model->short_name = $pay_types_default[$pay_type]['short_name']; $model->is_show = 1; $model->is_open = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess(); } private function initPayType() { $pay_types_default = PaymentTypes::payTypes(); $pay_types = []; foreach ($pay_types_default as $key => $val){ array_push($pay_types,$val['short_name']); } $this->pay_types = $pay_types; $this->savePayType(); $list = PaymentTypes::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, ]) ->select('name,short_name,is_show,is_open')->asArray()->all(); return $list; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $pay_types = PaymentTypes::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, ]) ->select('name,short_name,is_show,is_open')->asArray()->all(); if(!$pay_types){ $pay_types = $this->initPayType(); } $pay_types_default = PaymentTypes::payTypes(); foreach($pay_types_default as $key => $val){ if(!in_array($val['short_name'], array_column($pay_types, 'short_name'))){ $pay_type_item = [ 'name' => $val['name'], 'short_name' => $val['short_name'], 'is_show' => $val['disabled'] ? false : true, 'is_open' => $val['disabled'] ? false : true, ]; array_push($pay_types, $pay_type_item); } } foreach ($pay_types as $index => $item){ $item['is_show'] = $pay_types_default[$item['short_name']]['disabled'] ? false : true; $item['is_open'] = isset($item['is_open']) && $item['is_open'] == 1 ? true : false; $pay_types[$index] = $item; } $data = []; $data['pay_types'] = $pay_types; return $data; } }