Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

362 wiersze
12 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use backend\modules\zzcs\models\OrderTitleCancelRequest;
  4. use Yii;
  5. use yii\db\Expression;
  6. use yii\db\ActiveRecord;
  7. /**
  8. * This is the model class for table "order_title".
  9. *
  10. * @property integer $order_title_id
  11. * @property integer $order_title_type
  12. * @property integer $main_corp_id
  13. * @property string $create_date
  14. * @property integer $create_user_id
  15. * @property string $create_time
  16. * @property string $confirm_time
  17. * @property integer $update_user_id
  18. * @property string $update_time
  19. * @property string $end_time
  20. * @property integer $outside_sale_org_id
  21. * @property string $outside_order_no
  22. * @property string $order_title_prod_name
  23. * @property string $order_title_prod_description
  24. * @property string $start_date
  25. * @property string $start_time
  26. * @property string $cus_name
  27. * @property string $cus_phone
  28. * @property string $cus_id_no
  29. * @property string $cus_remark
  30. * @property integer $cus_id_type
  31. * @property integer $cus_num
  32. * @property string $order_title_all_price
  33. * @property string $order_title_per_price
  34. * @property string $order_title_all_cost
  35. * @property string $order_title_per_cost
  36. * @property string $order_title_all_affi
  37. * @property string $order_title_per_affi
  38. * @property string $order_prod_type
  39. * @property integer $order_pay_type
  40. * @property integer $order_title_status
  41. * @property string $order_passenger_list
  42. * @property string $order_title_memo
  43. * @property integer $cancel_flag
  44. * @property string $bus_order
  45. * @property string $ticket_order
  46. * @property string $hotel_order
  47. * @property integer $tourist_id
  48. * @property integer $adult_num
  49. * @property integer $child_num
  50. * @property integer $is_send_msg
  51. */
  52. class OrderTitle extends ActiveRecord
  53. {
  54. /**
  55. * @inheritdoc
  56. */
  57. public static function tableName()
  58. {
  59. return 'order_title';
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function rules()
  65. {
  66. return [
  67. [['main_corp_id', 'create_user_id', 'update_user_id', 'outside_sale_org_id', 'cus_id_type', 'cus_num', 'order_pay_type', 'order_title_status', 'cancel_flag', 'order_title_type', 'tourist_id', 'adult_num', 'child_num', 'is_send_msg', 'is_buy_insurance', 'is_connected_order'], 'integer'],
  68. [['order_title_prod_description', 'cus_remark', 'order_passenger_list', 'order_title_memo', 'outside_order_no'], 'string'],
  69. [['order_title_all_price', 'order_title_per_price', 'order_title_all_cost', 'order_title_per_cost', 'order_title_all_affi', 'order_title_per_affi'], 'number'],
  70. [['create_date', 'start_date'], 'string', 'max' => 10],
  71. [['create_time', 'confirm_time', 'update_time', 'end_time', 'end_date', 'cus_phone'], 'string', 'max' => 20],
  72. [['outside_order_no', 'cus_name', 'bus_order', 'ticket_order', 'hotel_order'], 'string', 'max' => 50],
  73. [['order_title_prod_name'], 'string', 'max' => 200],
  74. [['start_time'], 'string', 'max' => 5],
  75. [['cus_id_no'], 'string', 'max' => 30],
  76. [['order_prod_type'], 'string', 'max' => 3],
  77. ];
  78. }
  79. /**
  80. * @inheritdoc
  81. */
  82. public function attributeLabels()
  83. {
  84. return [
  85. 'order_title_id' => 'Order Title ID',
  86. 'order_title_type' => '组合订单种类:1自由选择(CS) 2跟团游(微信商城)。。。',
  87. 'main_corp_id' => '运营主体',
  88. 'create_date' => '下单日期',
  89. 'create_user_id' => '下单人',
  90. 'create_time' => '下单时刻',
  91. 'confirm_time' => '订单确认时间',
  92. 'update_user_id' => '最后更新人',
  93. 'update_time' => '最后更新时刻',
  94. 'end_date' => '游玩归来日期',
  95. 'end_time' => '订单完成或取消时间',
  96. 'outside_sale_org_id' => '渠道',
  97. 'outside_order_no' => '渠道订单号',
  98. 'order_title_prod_name' => '产品名(自动生成)',
  99. 'order_title_prod_description' => '产品明细',
  100. 'start_date' => '出发日期',
  101. 'start_time' => '出发时刻',
  102. 'cus_name' => '联系人',
  103. 'cus_phone' => '联系手机',
  104. 'cus_id_no' => '联系人身份证',
  105. 'cus_remark' => '备注',
  106. 'cus_id_type' => '联系人证件类型150身份证 153护照',
  107. 'cus_num' => '总人数',
  108. 'order_title_all_price' => '总收入',
  109. 'order_title_per_price' => '单人收入',
  110. 'order_title_all_cost' => '总成本',
  111. 'order_title_per_cost' => '单人成本',
  112. 'order_title_all_affi' => '总渠道佣金',
  113. 'order_title_per_affi' => '单人渠道佣金',
  114. 'order_prod_type' => '组合订单种类:[100]单车票[010]单酒店[001]单门票[110]车+酒[101]车+门[011]酒+门[111]车+酒+门',
  115. 'order_pay_type' => '组合订单支付方式',
  116. 'order_title_status' => '组合订单整体状态, 1:待确认 2: 已确认 3:已完成 4: 已取消。',
  117. 'order_passenger_list' => '出行人信息',
  118. 'order_title_memo' => '备注',
  119. 'cancel_flag' => 'Cancel Flag',
  120. 'bus_order' => '对应子巴士产品订单号,多个用逗号隔开',
  121. 'ticket_order' => '对应门票子产品订单号,多个用逗号隔开',
  122. 'hotel_order' => '对应酒店子产品订单号,多个用逗号隔开',
  123. 'tourist_id' => '自由行产品id,为0是组合订单',
  124. 'adult_num' => '自由行产品成人人数',
  125. 'child_num' => '自由行产品儿童人数',
  126. 'is_send_msg' => '自由行是否已发送短信',
  127. 'is_buy_insurance' => '是否购买保险',
  128. ];
  129. }
  130. /**
  131. * Function Description:获取组合订单信息判断是否可以取消
  132. * Function Name: getCheckCancelInfo
  133. * @param $order_title
  134. *
  135. * @return array|null|\yii\db\ActiveRecord
  136. *
  137. * @author 娄梦宁
  138. */
  139. public function getCheckCancelInfo($order_title)
  140. {
  141. $result = self::find()->select('order_title_type,tourist_id,order_title_status,is_buy_insurance,start_date')
  142. ->from(self::tableName())
  143. ->where(['order_title_id' => $order_title])
  144. ->limit(1)
  145. ->asArray()
  146. ->one();
  147. return $result;
  148. }
  149. /**
  150. * Function Description:获取自由行产品已确认未发预定短信订单
  151. * Function Name: getConfirmedOrders
  152. *
  153. * @return array
  154. *
  155. * @author 温依莅
  156. */
  157. public function getConfirmedOrders()
  158. {
  159. $res = self::find()->select([
  160. 'order_title_id',
  161. 'order_title_prod_name',
  162. 'cus_num',
  163. 'adult_num',
  164. 'child_num',
  165. 'start_date',
  166. 'order_title_type',
  167. 'tourist_id',
  168. 'order_title_status',
  169. 'is_send_msg',
  170. 'main_corp_id'
  171. ])->from(self::tableName())
  172. ->where([
  173. 'and',
  174. ['=', 'order_title_type', 2],
  175. ['>', 'tourist_id', 0],
  176. ['=', 'order_title_status', 2],
  177. ['=', 'is_send_msg', 0],
  178. ['=', 'cancel_flag', 0],
  179. ])->asArray()->all();
  180. return $res;
  181. }
  182. /**
  183. * Function Description:获取自由行产品的详细信息
  184. * Function Name: getTitleInfo
  185. * @param int $order_title_id
  186. * @return array
  187. *
  188. * @author 温依莅
  189. */
  190. public function getTitleInfo($order_title_id)
  191. {
  192. $select = [
  193. 'a.order_title_id',
  194. 'a.outside_order_no',
  195. 'a.order_title_prod_name',
  196. 'a.cus_phone',
  197. 'a.adult_num',
  198. 'a.child_num',
  199. 'a.cus_num',
  200. 'a.start_date',
  201. 'a.order_title_type',
  202. 'a.tourist_id',
  203. 'a.order_title_status',
  204. 'a.is_send_msg',
  205. 'a.is_connected_order',
  206. 'a.order_title_all_price',
  207. 'b.id',
  208. 'sequence_id' => new Expression("ifnull(b.sequence_id,'')"),
  209. 'request_status' => new Expression("ifnull(b.request_status,0)"),
  210. 'remark' => new Expression("ifnull(b.remark,'')")
  211. ];
  212. $res = self::find()->select($select)
  213. ->from(self::tableName() . ' a')
  214. ->leftJoin(OrderTitleCancelRequest::tableName() . ' b', 'b.order_title_id = a.order_title_id')
  215. ->where(['=', 'a.order_title_id', $order_title_id])
  216. ->orderBy('b.id desc')
  217. ->limit(1)
  218. ->asArray()
  219. ->one();
  220. return $res;
  221. }
  222. /**
  223. * Function Description:获取自由行产品的详细信息
  224. * Function Name: getCtripTitleInfo
  225. * @param int $outside_order_no
  226. * @return array
  227. *
  228. * @author 温依莅
  229. */
  230. public function getCtripTitleInfo($outside_order_no)
  231. {
  232. $select = [
  233. 'a.outside_sale_org_id',
  234. 'a.order_title_id',
  235. 'a.outside_order_no',
  236. 'a.order_title_prod_name',
  237. 'a.cus_phone',
  238. 'a.adult_num',
  239. 'a.child_num',
  240. 'a.cus_num',
  241. 'a.start_date',
  242. 'a.order_title_type',
  243. 'a.tourist_id',
  244. 'a.order_title_status',
  245. 'a.is_send_msg',
  246. 'a.is_connected_order',
  247. 'a.order_title_all_price',
  248. 'b.id',
  249. 'sequence_id' => new Expression("ifnull(b.sequence_id,'')"),
  250. 'request_status' => new Expression("ifnull(b.request_status,0)"),
  251. 'remark' => new Expression("ifnull(b.remark,'')")
  252. ];
  253. $res = self::find()->select($select)
  254. ->from(self::tableName() . ' a')
  255. ->leftJoin(OrderTitleCancelRequest::tableName() . ' b', 'b.order_title_id = a.order_title_id')
  256. ->where(['=', 'a.outside_order_no', $outside_order_no])
  257. ->orderBy('b.id desc')
  258. ->limit(1)
  259. ->asArray()
  260. ->one();
  261. return $res;
  262. }
  263. /**
  264. * Function Description:更新自由行产品短信发送状态
  265. * Function Name: updateMsgStatus
  266. * @param $order_title_id
  267. *
  268. * @return bool
  269. * @author 温依莅
  270. */
  271. public function updateMsgStatus($order_title_id)
  272. {
  273. $obj = self::findOne(['order_title_id' => $order_title_id]);
  274. if (!$obj) {
  275. return false;
  276. }
  277. $obj->is_send_msg = 1;
  278. if (false === $obj->update()) {
  279. return false;
  280. } else {
  281. return true;
  282. }
  283. }
  284. /**
  285. * Function Description:获取自由行产品信息(为了自由行下保险订单兼容巴士下保险订单发送短信)
  286. * Function Name: getTitleInfoById
  287. * @param $order_title_id
  288. *
  289. * @return array|null|ActiveRecord
  290. *
  291. * @author 田玲菲
  292. */
  293. public function getTitleInfoById($order_title_id)
  294. {
  295. $res = self::find()->select([
  296. 'order_title_id',
  297. 'order_title_prod_name',
  298. 'outside_sale_org_id',
  299. 'cus_phone',
  300. 'adult_num',
  301. 'child_num',
  302. 'start_date as run_date',
  303. 'start_date as prod_start_station_date',
  304. 'start_time as prod_start_station_time',
  305. 'create_time' => new Expression('concat(create_date,\' \',create_time)'),
  306. 'order_title_type',
  307. 'tourist_id',
  308. 'order_title_status',
  309. 'is_send_msg',
  310. ])->from(self::tableName())
  311. ->where([
  312. 'order_title_id' => $order_title_id
  313. ])->limit(1)->asArray()->one();
  314. return $res;
  315. }
  316. /**
  317. * Function Description:获取自由行订单信息
  318. * Function Name: getCtripOrderInfoById
  319. * @param $outside_order_no
  320. *
  321. * @return array|null|ActiveRecord
  322. *
  323. * @author 倪宗锋
  324. */
  325. public function getCtripOrderInfoById($outside_order_no)
  326. {
  327. $res = self::find()->select([
  328. 'order_title_id',
  329. 'order_title_prod_name',
  330. 'cus_phone',
  331. 'adult_num',
  332. 'child_num',
  333. 'start_date as run_date',
  334. 'start_date as prod_start_station_date',
  335. 'start_time as prod_start_station_time',
  336. 'create_time' => new Expression('concat(create_date,\' \',create_time)'),
  337. 'order_title_type',
  338. 'tourist_id',
  339. 'order_title_status',
  340. 'is_send_msg',
  341. ])->from(self::tableName())
  342. ->where([
  343. 'outside_order_no' => $outside_order_no
  344. ])->limit(1)->asArray()->one();
  345. return $res;
  346. }
  347. }