You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AliOrder.php 24 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. namespace backend\modules\hotel\models\Ali;
  3. use backend\modules\hotel\models\RunHotelDistrib;
  4. use backend\modules\hotel\models\OrderMain;
  5. use backend\modules\hotel\models\OperaHotelRoom;
  6. use Yii;
  7. use common\models\BaseSupplierSale;
  8. use backend\modules\hotel\models\CommonOrder;
  9. /**
  10. * This is the model class for table "{{%ali_order}}".
  11. *
  12. * @property integer $ID
  13. * @property string $CreateTime
  14. * @property string $TaoBaoOrderId
  15. * @property string $TaoBaoHotelId
  16. * @property string $HotelId
  17. * @property string $TaoBaoRoomTypeId
  18. * @property string $RoomTypeId
  19. * @property string $TaoBaoRatePlanId
  20. * @property string $RatePlanCode
  21. * @property string $Channel
  22. * @property string $TaoBaoGid
  23. * @property string $CheckIn
  24. * @property string $CheckOut
  25. * @property string $HourRent
  26. * @property string $EarliestArriveTime
  27. * @property string $LatestArriveTime
  28. * @property integer $RoomNum
  29. * @property integer $Occupancy
  30. * @property integer $PriceType
  31. * @property integer $IsMorningBuy
  32. * @property integer $InventoryType
  33. * @property string $TotalPrice
  34. * @property string $OtherFee
  35. * @property string $PaidPrice
  36. * @property string $TotalSellerPromotion
  37. * @property string $GTPrice
  38. * @property string $Currency
  39. * @property integer $PaymentType
  40. * @property string $ContactName
  41. * @property string $ContactTel
  42. * @property string $ContactEmail
  43. * @property string $DailyInfos
  44. * @property string $OriDailyInfos
  45. * @property string $DisDailyInfos
  46. * @property string $TravelInfo
  47. * @property string $OrderGuests
  48. * @property string $Comment
  49. * @property integer $GuaranteeType
  50. * @property string $MemberInfo
  51. * @property string $AlipayTradeNo
  52. * @property string $VoucherInfos
  53. * @property string $CreditCardInfo
  54. * @property string $InvoiceInfo
  55. * @property string $PackageInfos
  56. * @property string $Extensions
  57. * @property string $CustomerNumber
  58. */
  59. class AliOrder extends \yii\db\ActiveRecord
  60. {
  61. CONST ORDER_CONFIRMED = 1; //订单已经确认
  62. CONST ORDER_NO_CONFIRMED = 2; //订单未确认
  63. CONST ORDER_COMFIRMING = 3;// 订单等待处理中;
  64. CONST ORDER_CANCELED = 4; //订单已取消
  65. CONST ORDER_CHECKIN = 5; //已入住
  66. CONST ORDER_CLOSED = 6; //订单关闭
  67. CONST ORDER_DELETED = 7; //订单删除
  68. CONST ORDER_NOSHOW = 8; //客人NOSHOW
  69. CONST ORDER_CHECKOUT = 9; //客人离店
  70. //注意:这里的错误码(非0)最终返回接口前面都是需要加-号的
  71. CONST RESPONSE_SUCCESS = 0; //预定成功
  72. CONST RESPONSE_SOLDOUT = 101; //满房或者关房
  73. CONST RESPONSE_CUSTORM = 102; //自定义原因
  74. CONST RESPONSE_PRICEERROR = 103; //淘宝酒店下单请求里的每日价格、总价与第三方系统的每日价格、总价不匹配
  75. CONST RESPONSE_SYSERROR = 104; //第三方系统异常
  76. CONST RESPONSE_REPEATBOOK = 106;//重复预定
  77. CONST RESPONSE_NOT_HOTEL_ID = 113;//房型不存在
  78. CONST RESPONSE_NOT_ROOM_TYPE = 114;//房型不存在
  79. CONST RESPONSE_NOT_RATE_PLAN = 115;//价格政策不存在
  80. CONST RESPONSE_PARAM_ERROR = 116;//参数错误:{具体参数不合法说明}
  81. CONST RESPONSE_MSG = [
  82. self::RESPONSE_SUCCESS => '预定成功',
  83. self::RESPONSE_SOLDOUT => '满房',
  84. self::RESPONSE_CUSTORM => '自定义原因',
  85. self::RESPONSE_PRICEERROR => '价格校验失败',
  86. self::RESPONSE_SYSERROR => '系统异常',
  87. self::RESPONSE_REPEATBOOK => '重复预定',
  88. self::RESPONSE_NOT_HOTEL_ID => '酒店ID不存在',
  89. self::RESPONSE_NOT_ROOM_TYPE => '房型不存在',
  90. self::RESPONSE_NOT_RATE_PLAN => '价格政策不存在',
  91. self::RESPONSE_PARAM_ERROR => '参数错误',
  92. ];
  93. public $room_type; //下单辅助参数
  94. public $cus_list = '';
  95. public $new_room_list = '';
  96. public $zz_order_id; //蜘蛛订单号
  97. public $apiParas = array();
  98. /**
  99. * @inheritdoc
  100. */
  101. public static function tableName()
  102. {
  103. return '{{%ali_order}}';
  104. }
  105. /**
  106. * Author:Steven
  107. * Desc:设置场景
  108. * @return array
  109. */
  110. public function scenarios()
  111. {
  112. return [
  113. //酒店试单
  114. 'ValidateRQ' => ['TaoBaoHotelId', 'HotelId', 'TaoBaoRoomTypeId', 'RoomTypeId', 'TaoBaoRatePlanId', 'RatePlanCode',
  115. 'TaoBaoGid', 'CheckIn', 'CheckOut', 'RoomNum', 'CustomerNumber', 'PaymentType', 'Extensions'
  116. ],
  117. //创建订单
  118. 'BookRQ' => ['TaoBaoOrderId', 'TaoBaoHotelId', 'HotelId', 'TaoBaoRoomTypeId', 'RoomTypeId', 'TaoBaoRatePlanId', 'RatePlanCode',
  119. 'Channel', 'TaoBaoGid', 'CheckIn', 'CheckOut', 'HourRent', 'EarliestArriveTime', 'LatestArriveTime', 'RoomNum', 'Occupancy',
  120. 'PriceType', 'IsMorningBuy', 'InventoryType', 'TotalPrice', 'OtherFee', 'PaidPrice', 'TotalSellerPromotion', 'Currency',
  121. 'PaymentType', 'ContactName', 'ContactTel', 'ContactEmail', 'DailyInfos', 'OriDailyInfos', 'DisDailyInfos', 'TravelInfo', 'OrderGuests',
  122. 'Comment', 'GuaranteeType', 'MemberInfo', 'AlipayTradeNo', 'VoucherInfos', 'CreditCardInfo', 'InvoiceInfo', 'PackageInfos', 'Extensions', 'zz_order_id'
  123. ],
  124. ];
  125. }
  126. /**
  127. * @inheritdoc
  128. */
  129. public function rules()
  130. {
  131. return [
  132. //酒店试单
  133. [['TaoBaoHotelId', 'HotelId', 'TaoBaoRoomTypeId', 'RoomTypeId', 'TaoBaoRatePlanId', 'RatePlanCode', 'TaoBaoGid', 'CheckIn',
  134. 'CheckOut', 'RoomNum', 'CustomerNumber', 'PaymentType'], 'required', 'on' => ['ValidateRQ']],
  135. [['HotelId', 'RoomTypeId', 'RatePlanCode', ''], 'string', 'max' => 64, 'on' => ['ValidateRQ']],
  136. [['RoomNum', 'CustomerNumber'], 'integer', 'min' => 1, 'max' => 9, 'message' => '入住人数或房间数量超限', 'on' => ['ValidateRQ']],
  137. // [['CustomerNumber'], 'match', 'pattern' => '/^[1-9]{1}$/', 'message' => '入住人数超限', 'on' => ['ValidateRQ']],
  138. [['CheckIn', 'CheckOut'], 'date', 'format' => 'yyyy-mm-dd', 'on' => ['ValidateRQ']],
  139. //创建订单
  140. [['TaoBaoOrderId', 'TaoBaoHotelId', 'HotelId', 'TaoBaoRoomTypeId', 'RoomTypeId', 'TaoBaoRatePlanId', 'RatePlanCode', 'CheckIn',
  141. 'CheckOut', 'EarliestArriveTime', 'LatestArriveTime', 'RoomNum', 'Occupancy', 'TotalPrice', 'Currency', 'PaymentType',
  142. 'ContactName', 'ContactTel', 'DailyInfos', 'OrderGuests'], 'required', 'on' => ['BookRQ']],
  143. [['HotelId', 'RoomTypeId', 'RatePlanCode'], 'string', 'max' => 64, 'on' => ['BookRQ']],
  144. [['TaoBaoHotelId'], 'validateOrderExist', 'on' => ['BookRQ']],
  145. [['RatePlanCode'], 'validateDiret'],
  146. [['CreateTime', 'CheckIn', 'CheckOut', 'EarliestArriveTime', 'LatestArriveTime', 'OrderId', 'zz_order_id'], 'safe'],
  147. [['TaoBaoHotelId', 'HotelId', 'TaoBaoRoomTypeId', 'RoomTypeId', 'TaoBaoRatePlanId', 'RatePlanCode', 'TaoBaoGid', 'EarliestArriveTime', 'LatestArriveTime', 'Occupancy'], 'required'],
  148. // [['RoomNum', 'Occupancy', 'PriceType', 'IsMorningBuy', 'InventoryType', 'PaymentType', 'GuaranteeType'], 'integer'],
  149. ];
  150. }
  151. /**
  152. * @inheritdoc
  153. */
  154. public function attributeLabels()
  155. {
  156. return [
  157. 'ID' => 'ID',
  158. 'CreateTime' => '创建时间',
  159. 'TaoBaoOrderId' => '淘宝订单id',
  160. 'TaoBaoHotelId' => '淘宝酒店id',
  161. 'OrderId' => '蜘蛛订单号',
  162. 'HotelId' => 'OTA酒店id,这里即我们系统中的酒店id',
  163. 'TaoBaoRoomTypeId' => '淘宝房型id',
  164. 'RoomTypeId' => 'OTA房型id,即我们系统中的房型id',
  165. 'TaoBaoRatePlanId' => '淘宝价格计划id',
  166. 'RatePlanCode' => 'OTA价格计划id,即opera_hotel_room中的id',
  167. 'Channel' => '酒店投放渠道 阿里协议价: 阿里员工 : A ;HRS商旅价: 阿里员工 + 阿里商旅用户 : A,O;公开价: 阿里员工 + 阿里商旅用户 + 飞猪用户:A,O,H',
  168. 'TaoBaoGid' => '淘宝酒店商品ID',
  169. 'CheckIn' => '入住时间',
  170. 'CheckOut' => '离店时间',
  171. 'HourRent' => '小时房(时间取Checkin/Checkout对应的具体时间)',
  172. 'EarliestArriveTime' => '最早到店时间',
  173. 'LatestArriveTime' => '最晚到店时间',
  174. 'RoomNum' => '房间数量(最大为9)',
  175. 'Occupancy' => '入住人数,目前支持一笔订单最多入住人数15。例如别墅订单存在多人的情况',
  176. 'PriceType' => '下单使用的价格类型:0默认值;1变价订单价格标记',
  177. 'IsMorningBuy' => '是否为凌晨房,0不是,1是,默认0',
  178. 'InventoryType' => '下单使用的库存类型:0.未知;1限售库存;2保留房库存;3物理库存;4超预定库存',
  179. 'TotalPrice' => '订单总价(分)',
  180. 'OtherFee' => '授权杂费金额(分)',
  181. 'PaidPrice' => '已付金额(预付和在线预约场景下启用)',
  182. 'TotalSellerPromotion' => '卖家优惠总金额',
  183. 'GTPrice' => '订单担保金额(担保订单场景下启用)',
  184. 'Currency' => '货币类型(现在只支持一种)',
  185. 'PaymentType' => '支付方式1预付、5面付、6后付(现在只有1、5、6)',
  186. 'ContactName' => '联系人姓名',
  187. 'ContactTel' => '联系人电话',
  188. 'ContactEmail' => '联系人邮箱',
  189. 'DailyInfos' => '每日价格',
  190. 'OriDailyInfos' => '每日原始价格 当存在卖家优惠的时候启用',
  191. 'DisDailyInfos' => '每日折扣价格 当存在卖家优惠的时候启动',
  192. 'TravelInfo' => 'Travel Info',
  193. 'OrderGuests' => '入住人信息',
  194. 'Comment' => '开票项目 一段文本(例如:代订房费、住宿费、会议费、旅游费等)',
  195. 'GuaranteeType' => '担保类型 0 无担保 1 峰时首晚担保 2峰时全额担保 3全天首晚担保 4全天全额担保',
  196. 'MemberInfo' => 'Member Info',
  197. 'AlipayTradeNo' => '支付宝交易号,只有预付的先付款后下单会有这个',
  198. 'VoucherInfos' => '订单优惠节点 当订单中含有优惠(房券/代金券/立减等)',
  199. 'CreditCardInfo' => 'Credit Card Info',
  200. 'InvoiceInfo' => 'Invoice Info',
  201. 'PackageInfos' => 'Package Infos',
  202. 'Extensions' => '扩展字段json,用于处理特殊OTA个性需求添加的扩展字段 {\"key\":\"value\"} 一些优惠信息等在扩展字段中传递',
  203. 'CustomerNumber' => 'Customer Number',
  204. ];
  205. }
  206. /**
  207. * Author:Steven
  208. * Desc:自定义setAttributes
  209. * @param array $values
  210. * @param bool $safeOnly
  211. */
  212. /*public function setAttributes($values, $safeOnly = true)
  213. {
  214. if (is_array($values)) {
  215. $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
  216. foreach ($values as $name => $value) {
  217. if (isset($attributes[$name])) {
  218. if (is_array($value) && !empty($value)) {
  219. $this->$name = json_encode($value);
  220. } else {
  221. $this->$name = $value;
  222. }
  223. } elseif ($safeOnly) {
  224. $this->onUnsafeAttribute($name, $value);
  225. }
  226. }
  227. }
  228. }*/
  229. /**
  230. * Author:Steven
  231. * Desc:加载数据 主要用于阿里创建订单
  232. * @param $data
  233. * @param null $formName
  234. * @return bool
  235. */
  236. /*public function load($data, $formName = null)
  237. {
  238. $scope = $formName === null ? $this->formName() : $formName;
  239. if ($scope === '' && !empty($data)) {
  240. $this->setAttributes($data, false);
  241. //构造下单需要的参数
  242. $this->cus_list = "{{$this->ContactName}{$this->ContactEmail}," . ($this->ContactTel) . "," .
  243. Yii::$app->params['ali']['base_user_id'] . "|" . time() . "|0|{$this->Comment}}";
  244. $supplier = BaseSupplier::findOne(['ID' => Yii::$app->params['ali']['supplier_id']]);
  245. if ($supplier == null) {
  246. return false;
  247. }
  248. $commissionRule = $supplier->getCommissionRule(BaseSupplierSale::SALE_HOTEL);
  249. if ($commissionRule != null && $commissionRule->COMMISION_TYPE == BaseSupplierSale::TYPE_CHANNEL) {
  250. $base_com = $commissionRule->BACK_PERCENT;
  251. } else if ($commissionRule == null) {
  252. $this->addError('Channel', '没有对应渠道销售');
  253. return false;
  254. } else {
  255. $base_com = 0;
  256. $this->Spider_sale_type = $commissionRule->SALE_TYPE;
  257. }
  258. if (isset($this->DailyInfos['DailyInfo'])) {
  259. foreach ($this->DailyInfos['DailyInfo'] as $DailyInfo) {
  260. $commission = ($base_com * $DailyInfo['Price']) / 100;
  261. $this->new_room_list .= "{''" . $DailyInfo['Day'] . "''," . $this->RoomNum . "," . $DailyInfo['Price'] . "," . $this->RoomNum * $commission . "}";
  262. }
  263. }
  264. return true;
  265. } elseif (isset($data[$scope])) {
  266. $this->setAttributes($data[$scope]);
  267. return true;
  268. } else {
  269. return false;
  270. }
  271. }*/
  272. /**
  273. * Author:Steven
  274. * Desc:加载数据 主要用于阿里创建订单
  275. * @param $data
  276. * @param null $formName
  277. * @return bool
  278. */
  279. public function loadBook($data, $formName = null)
  280. {
  281. $scope = $formName === null ? $this->formName() : $formName;
  282. if ($scope === '' && !empty($data)) {
  283. $this->setAttributes($data, false);
  284. //构造下单需要的参数
  285. $this->cus_list = "{{$this->ContactName}{$this->ContactEmail}," . ($this->ContactTel) . "," .
  286. Yii::$app->params['ali']['base_user_id'] . "|" . time() . "|0|{$this->Comment}}";
  287. $supplier = \common\models\BaseSupplier::findOne(['ID' => Yii::$app->params['ali']['supplier_id']]);
  288. if ($supplier == null) {
  289. return false;
  290. }
  291. $commissionRule = $supplier->getCommissionRule(BaseSupplierSale::SALE_HOTEL);
  292. if ($commissionRule != null && $commissionRule->COMMISION_TYPE == BaseSupplierSale::TYPE_CHANNEL) {
  293. $base_com = $commissionRule->BACK_PERCENT;
  294. } else if ($commissionRule == null) {
  295. $this->addError('Channel', '没有对应渠道销售');
  296. return false;
  297. } else {
  298. $base_com = 0;
  299. $this->Spider_sale_type = $commissionRule->SALE_TYPE;
  300. }
  301. if (isset($this->DailyInfos['DailyInfo'])) {
  302. foreach ($this->DailyInfos['DailyInfo'] as $DailyInfo) {
  303. $commission = ($base_com * $DailyInfo['Price']) / 100;
  304. $this->new_room_list .= "{''" . $DailyInfo['Day'] . "''," . $this->RoomNum . "," . $DailyInfo['Price'] . "," . $this->RoomNum * $commission . "}";
  305. }
  306. }
  307. return true;
  308. } elseif (isset($data[$scope])) {
  309. $this->setAttributes($data[$scope]);
  310. return true;
  311. } else {
  312. return false;
  313. }
  314. }
  315. /**
  316. * Author:Steven
  317. * Desc:验证订单是否存在,避免重复下单
  318. * @param $attribute
  319. * @param $params
  320. */
  321. public function validateOrderExist($attribute, $params)
  322. {
  323. $res = OrderMain::find()->where([
  324. 'OUTSIDE_ORDER_NO' => "{$this->TaoBaoOrderId}",
  325. 'ORDER_PROD_TYPE' => OrderMain::ORDER_PROD_TYPE_MAIN,
  326. 'PARENT_ORDER_ID' => 0,
  327. 'CANCEL_FLAG' => 0
  328. ])->limit(1)->asArray()->one();
  329. if (!empty($res)) {
  330. $this->addError($attribute, self::RESPONSE_REPEATBOOK);
  331. }
  332. }
  333. /**
  334. * Author:Steven
  335. * Desc:判断是都符合直连需求 验证酒店、房型、RP等信息的有效性
  336. * @return bool
  337. */
  338. public function validateDiret($attribute, $params)
  339. {
  340. $model = OperaHotelRoom::find()->select(['a.ID', 'a.HOTEL_ID', 'a.PARENT_ROOM_TYPE', 'a.ROOM_TYPE', 'c.ChannelHotelId', 'b.ChannelRoomId', 'a.RP_ID'])
  341. ->leftJoin('channel_room_relation b', 'a.PARENT_ROOM_TYPE=RoomId and b.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
  342. ->leftJoin('channel_hotel_relation c', 'a.HOTEL_ID=c.HotelId and c.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
  343. ->from('opera_hotel_room a')
  344. ->where([
  345. 'a.ID' => $this->RatePlanCode
  346. ])->asArray()->one();
  347. if (empty($model) || $model['HOTEL_ID'] != $this->HotelId || $model['ChannelHotelId'] != $this->TaoBaoHotelId) {
  348. $this->addError($attribute, self::RESPONSE_NOT_HOTEL_ID);
  349. } elseif ($model['PARENT_ROOM_TYPE'] != $this->RoomTypeId || $model['ChannelRoomId'] != $this->TaoBaoRoomTypeId) {
  350. $this->addError($attribute, self::RESPONSE_NOT_ROOM_TYPE);
  351. } elseif ($model['RP_ID'] != $this->TaoBaoRatePlanId) {
  352. $this->addError($attribute, self::RESPONSE_NOT_RATE_PLAN);
  353. }
  354. $this->room_type = $model['ROOM_TYPE']; //在验证的时候顺便初始化子房型ID
  355. return true;
  356. }
  357. /**
  358. * Notes:阿里酒店下单接口
  359. * User: Steven
  360. * Date: 2018/1/16
  361. * Time: 11:43
  362. * @return mixed
  363. * @throws \yii\db\Exception
  364. */
  365. public function bookOrder()
  366. {
  367. $params = [
  368. 'CreateUserID' => Yii::$app->params['ali']['base_user_id'],
  369. 'OrderID' => $this->TaoBaoOrderId, //渠道订单号
  370. 'HotelID' => $this->HotelId, //酒店ID
  371. 'RoomID' => $this->RatePlanCode, //房型ID
  372. 'DistribID' => Yii::$app->params['ali']['supplier_id'],//渠道ID
  373. 'RoomNum' => $this->RoomNum, //房间数量
  374. 'CheckIn' => $this->CheckIn, //入住日期
  375. 'CheckOut' => $this->CheckOut, //离店日期,
  376. 'TotalPrice' => $this->TotalPrice / 100,//订单总价
  377. 'Currency' => $this->Currency == 'CNY' ? 'RMB' : '', //币种
  378. 'ContactName' => $this->ContactName,//联系人姓名
  379. 'ContactTel' => $this->ContactTel, //联系人电话
  380. 'PayType' => CommonOrder::PAY_TYPE_CREDIT, // 638:支付宝支付; 221:现金支付 ;275:授信支付;278:微信支付
  381. 'PayTradeNo' => $this->AlipayTradeNo, //支付流水号
  382. 'OrderGuests' => $this->getGuestsName(), //入住人信息
  383. 'CommentType' => 2, //公共备注
  384. 'Comment' => empty($this->Comment) ? '' : $this->Comment, //客人备注
  385. 'NeedInvoice' => empty($this->InvoiceInfo['NeedInvoice']) ? 0 : $this->InvoiceInfo['NeedInvoice'],
  386. 'InvoiceInfos' => $this->InvoiceInfo,
  387. 'RoomPrices' => $this->getRoomPrices(),
  388. 'OrderTitleID' => 0
  389. ];
  390. $new_order = new CommonOrder(['scenario' => 'BookHotelOrder']);
  391. if ($new_order->load($params, '') && $new_order->validate()) {
  392. $res = $new_order->bookHotelOrder();
  393. if ($res['code'] == CommonOrder::RETURN_CODE_SUCCESS) {
  394. $this->zz_order_id = $res['data']['order_id'];
  395. return self::RESPONSE_SUCCESS;
  396. }
  397. $return_code = self::RESPONSE_SYSERROR;
  398. if ($res['code'] == CommonOrder::RETURN_CODE_UNAUTHORIZED || $res['code'] == CommonOrder::RETURN_CODE_ROOM_CLOSED ||
  399. $res['code'] == CommonOrder::RETURN_CODE_STOCK_FAIL) {
  400. $return_code = self::RESPONSE_SOLDOUT;
  401. }
  402. if ($res['code'] == CommonOrder::RETURN_CODE_PRICE_FAIL) {
  403. return self::RESPONSE_PRICEERROR;
  404. }
  405. if ($res['code'] == CommonOrder::RETURN_CODE_PROGRAM_FAIL) {
  406. return self::RESPONSE_SYSERROR;
  407. }
  408. return $return_code;
  409. } else {
  410. $error = array_values($new_order->getFirstErrors());
  411. return self::RESPONSE_SYSERROR;
  412. }
  413. }
  414. /**
  415. * Author:Steven
  416. * Desc:验证产品是否可定
  417. * @param $attribute
  418. * @param $params
  419. */
  420. public function validateBook()
  421. {
  422. $end_date = date('Y-m-d', strtotime("-1 day", strtotime($this->CheckOut)));
  423. $data = RunHotelDistrib::getAvailProduct($this->RatePlanCode, $this->CheckIn, $end_date);
  424. $dailyInventory_flag = true; //房型是否可定标识
  425. $precisDailyPrice_flag = true; //价格是否正确标识
  426. foreach ($data as $item) {
  427. $dailyInventory[] = [
  428. 'date' => $item['RUN_DATE'],
  429. 'inventory' => 0
  430. ];
  431. $precisDailyPrice[] = [
  432. 'date' => $item['RUN_DATE'],
  433. 'price' => $item['PROD_PRICE'] * 100
  434. ];
  435. if ($item['RUN_STATUS'] == 329 || $item['AUTHORITY_STATUS'] == 0 || $item['ROOM_RUN_STATUS'] == 0 || $item['ROOM_IS_ONSALE'] == 0 || $item['IS_ONSALE'] == 0 || $this->RoomNum > $item['REMAINING_COUNT']) { //检查是否关
  436. //表示满房
  437. $dailyInventory_flag = false;
  438. $dailyInventory['reason'] = '满房';
  439. }
  440. //需要校验价格是否正确
  441. // $DailyInfos = json_decode($this->DailyInfos, true);
  442. $dailyInfo = isset($this->DailyInfos['DailyInfo'][0]) ? $this->DailyInfos['DailyInfo'] : $this->DailyInfos;
  443. foreach ($dailyInfo as $value) {
  444. if ($value['Day'] == $item['RUN_DATE']) {
  445. if ($item['PROD_PRICE'] * 100 != $value['Price']) { //价格(分)
  446. $precisDailyPrice_flag = false;
  447. $precisDailyPrice['reason'] = '价格校验失败';
  448. }
  449. }
  450. }
  451. }
  452. if (!$dailyInventory_flag || empty($data)) {
  453. return ['ResultCode' => '-' . self::RESPONSE_SOLDOUT, 'Message' => json_encode($dailyInventory)];
  454. }
  455. if (!$precisDailyPrice_flag) {
  456. return ['ResultCode' => '-' . self::RESPONSE_PRICEERROR, 'Message' => json_encode($precisDailyPrice)];
  457. }
  458. return ['ResultCode' => self::RESPONSE_SUCCESS, 'Message' => ''];
  459. }
  460. /**
  461. * Notes:获取入住人的信息
  462. * User: Steven
  463. * Date: 2018/1/25
  464. * Time: 14:30
  465. * @return array
  466. */
  467. public function getGuestsName()
  468. {
  469. $Guest_arr = [];
  470. $OrderGuests = isset($this->OrderGuests['OrderGuest']['Name']) ? $this->OrderGuests : $this->OrderGuests['OrderGuest'];
  471. foreach ($OrderGuests as $OrderGuest) {
  472. $Guest_arr[] = [
  473. 'Name' => $OrderGuest['Name']
  474. ];
  475. }
  476. if (empty($Guest_arr)) {
  477. $Guest_arr[0] = [
  478. 'Name' => $this->ContactName
  479. ];
  480. }
  481. return $Guest_arr;
  482. }
  483. /**
  484. * Notes:
  485. * User: Steven
  486. * Date: 2018/1/16
  487. * Time: 15:52
  488. */
  489. public function getRoomPrices()
  490. {
  491. $room_prices = [];
  492. $DailyInfos = isset($this->DailyInfos['DailyInfo']['Day']) ? $this->DailyInfos : $this->DailyInfos['DailyInfo'];
  493. foreach ($DailyInfos as $item) {
  494. $room_prices[] = [
  495. 'RunDate' => $item['Day'],
  496. 'Price' => $item['Price'] / 100
  497. ];
  498. }
  499. return $room_prices;
  500. }
  501. public function beforeSave($insert)
  502. {
  503. if ($this->isNewRecord) {
  504. $this->CreateTime = date('Y-m-d H:i:s', time());
  505. $this->OrderGuests = is_array($this->OrderGuests) ? json_encode($this->OrderGuests) : $this->OrderGuests;
  506. $this->InvoiceInfo = is_array($this->InvoiceInfo) ? json_encode($this->InvoiceInfo) : $this->InvoiceInfo;
  507. $this->DailyInfos = is_array($this->DailyInfos) ? json_encode($this->DailyInfos) : $this->DailyInfos;
  508. }
  509. return parent::beforeSave($insert);
  510. }
  511. }