Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

354 рядки
11 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. use yii\db\Expression;
  6. /**
  7. * This is the model class for table "opera_line".
  8. *
  9. * @property integer $LINE_ID
  10. * @property integer $CREATE_USER_ID
  11. * @property string $CREATE_TIME
  12. * @property integer $UPDATE_USER_ID
  13. * @property string $UPDATE_TIME
  14. * @property integer $CANCEL_FLAG
  15. * @property integer $IF_DISABLED
  16. * @property string $LINE_NAME
  17. * @property string $LINE_CODE
  18. * @property integer $LINE_TYPE
  19. * @property integer $LINE_SUB_TYPE
  20. * @property integer $IS_ONSALE
  21. * @property integer $SALE_EXPIRED_TYPE
  22. * @property string $SALE_EXPIRED_TIME
  23. * @property integer $MAIN_CORP_ID
  24. * @property integer $TOP_ORG_ID
  25. * @property integer $ORG_ID
  26. * @property integer $PRODUCT_TYPE
  27. * @property string $LINE_DESCRIBE
  28. * @property integer $DISP_ORDER
  29. * @property integer $TAILOR_TYPE
  30. * @property integer $TAILOR_FLAG
  31. * @property integer $ALLOW_SELECT_SEAT
  32. */
  33. class OperaLine extends \yii\db\ActiveRecord
  34. {
  35. /**
  36. * @inheritdoc
  37. */
  38. public static function tableName()
  39. {
  40. return 'opera_line';
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function rules()
  46. {
  47. return [
  48. [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'IF_DISABLED', 'LINE_TYPE', 'LINE_SUB_TYPE', 'IS_ONSALE', 'SALE_EXPIRED_TYPE', 'MAIN_CORP_ID', 'TOP_ORG_ID', 'ORG_ID', 'PRODUCT_TYPE', 'DISP_ORDER', 'TAILOR_TYPE', 'TAILOR_FLAG', 'ALLOW_SELECT_SEAT', 'RUN_DUTY_ID'], 'integer'],
  49. [['CREATE_TIME', 'LINE_NAME'], 'required'],
  50. [['UPDATE_TIME'], 'safe'],
  51. [['LINE_DESCRIBE', 'REMARK'], 'string'],
  52. [['CREATE_TIME'], 'string', 'max' => 20],
  53. [['LINE_NAME'], 'string', 'max' => 200],
  54. [['LINE_CODE'], 'string', 'max' => 30],
  55. [['SALE_EXPIRED_TIME'], 'string', 'max' => 10],
  56. ];
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'LINE_ID' => 'Line ID',
  65. 'CREATE_USER_ID' => 'Create User ID',
  66. 'CREATE_TIME' => 'Create Time',
  67. 'UPDATE_USER_ID' => 'Update User ID',
  68. 'UPDATE_TIME' => 'Update Time',
  69. 'CANCEL_FLAG' => 'Cancel Flag',
  70. 'IF_DISABLED' => 'If Disabled',
  71. 'LINE_NAME' => 'Line Name',
  72. 'LINE_CODE' => 'Line Code',
  73. 'LINE_TYPE' => 'Line Type',
  74. 'LINE_SUB_TYPE' => 'Line Sub Type',
  75. 'IS_ONSALE' => 'Is Onsale',
  76. 'SALE_EXPIRED_TYPE' => 'Sale Expired Type',
  77. 'SALE_EXPIRED_TIME' => 'Sale Expired Time',
  78. 'MAIN_CORP_ID' => 'Main Corp ID',
  79. 'TOP_ORG_ID' => 'Top Org ID',
  80. 'ORG_ID' => 'Org ID',
  81. 'PRODUCT_TYPE' => 'Product Type',
  82. 'LINE_DESCRIBE' => 'Line Describe',
  83. 'DISP_ORDER' => 'Disp Order',
  84. 'TAILOR_TYPE' => 'Tailor Type',
  85. 'TAILOR_FLAG' => 'Tailor Flag',
  86. 'ALLOW_SELECT_SEAT' => 'Allow Select Seat',
  87. 'RUN_DUTY_ID' => 'Run Duty Id',
  88. 'REMARK' => 'Remark',
  89. ];
  90. }
  91. /**
  92. * Function Description:获取动态巴士相关信息
  93. * Function Name: getDynamicInfo
  94. * @param $line_id
  95. *
  96. * @return array
  97. *
  98. * @author 温依莅
  99. */
  100. static public function getDynamicInfo($line_id)
  101. {
  102. $res = self::find()->select([
  103. 'ol.line_id', 'ol.product_type', 'ol.line_type', 'ol.main_corp_id', 'otp.cost_price', 'otp.product_price as prod_price', 'otp.product_price as cus_price'
  104. ])->from('opera_line ol')
  105. ->leftJoin('opera_tailor_product otp', 'ol.product_type=otp.id')
  106. ->where([
  107. 'and',
  108. ['=', 'ol.line_id', $line_id],
  109. ['>', 'ol.product_type', 0],
  110. ['=', 'ol.is_onsale', 1],
  111. ['=', 'ol.if_disabled', 0],
  112. ['=', 'otp.is_onsale', 1],
  113. ['=', 'otp.cancel_flag', 0]
  114. ])->asArray()->one();
  115. return $res;
  116. }
  117. /**
  118. * Function Description:检查线路编号是否存在
  119. * Function Name: checkLineExists
  120. * @param $line_code
  121. *
  122. * @return array|null|ActiveRecord
  123. *
  124. * @author 李健
  125. */
  126. public function checkLineExists($line_code)
  127. {
  128. $where = ['and'];
  129. $where[] = ['=', 'line_code', $line_code];
  130. $where[] = ['=', 'cancel_flag', 0];
  131. $res = self::find()
  132. ->select('line_id')
  133. ->from(self::tableName())
  134. ->where($where)
  135. ->asArray()
  136. ->one();
  137. return $res;
  138. }
  139. /**
  140. * Function Description:插入信息
  141. * Function Name: insertInfo
  142. * @param $user_id
  143. * @param $user_id
  144. * @param $line_name
  145. * @param $line_code
  146. * @param $line_type
  147. * @param $line_sub_type
  148. * @param $time_type
  149. * @param $time_info
  150. * @param $supply_id
  151. * @param $main_corp_id
  152. * @param $allow_select_seat
  153. *
  154. * @return bool|string
  155. *
  156. * @author 李健
  157. */
  158. public function insertInfo($user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_select_seat, $remark, $run_duty_id)
  159. {
  160. try {
  161. $this->CREATE_USER_ID = $user_id;
  162. $this->CREATE_TIME = date('Y-m-d H:i:s');
  163. $this->UPDATE_USER_ID = $user_id;
  164. $this->LINE_NAME = $line_name;
  165. $this->LINE_CODE = $line_code;
  166. $this->LINE_TYPE = $line_type;
  167. $this->LINE_SUB_TYPE = $line_sub_type;
  168. $this->SALE_EXPIRED_TYPE = $time_type;
  169. $this->SALE_EXPIRED_TIME = $time_info;
  170. $this->ORG_ID = $supply_id;
  171. $this->MAIN_CORP_ID = $main_corp_id;
  172. $this->ALLOW_SELECT_SEAT = $allow_select_seat;
  173. $this->REMARK = $remark;
  174. $this->RUN_DUTY_ID = $run_duty_id;
  175. $this->save();
  176. return \Yii::$app->db->lastInsertID;
  177. } catch (Exception $e) {
  178. return false;
  179. }
  180. }
  181. /**
  182. * Function Description:获取线路是否可换做
  183. * Function Name: getLineSeatAllow
  184. * @param $line_id
  185. *
  186. * @return array|null|ActiveRecord
  187. *
  188. * @author 娄梦宁
  189. */
  190. public function getLineSeatAllow($line_id)
  191. {
  192. return self::find()->select('allow_select_seat')->from(self::tableName())
  193. ->where(['line_id' => $line_id])->asArray()->one();
  194. }
  195. /**
  196. * Function Description:得到线路详细信息
  197. * Function Name: getLineDetail
  198. * @param $line_id
  199. *
  200. * @return array|\yii\db\ActiveRecord[]
  201. *
  202. * @author 李健
  203. */
  204. public function getLineDetail($line_id)
  205. {
  206. $select = [
  207. 'l.tailor_flag',
  208. 'l.line_id',
  209. 'l.line_name',
  210. 'l.line_code',
  211. 'l.line_type',
  212. 'l.org_id',
  213. 'l.run_duty_id',
  214. 'l.sale_expired_type',
  215. 'l.sale_expired_time',
  216. 's.order_id',
  217. 's.res_id',
  218. 's.start_minutes',
  219. 's.inout_type',
  220. 's.checkport_res_id',
  221. 's.area_id',
  222. 's.distance',
  223. 'l.allow_select_seat',
  224. 'l.remark'
  225. ];
  226. $where = ['and'];
  227. $where[] = ['=', 'l.cancel_flag', 0];
  228. $where[] = ['=', 's.cancel_flag', 0];
  229. $where[] = ['=', 'l.line_id', $line_id];
  230. $res = self::find()
  231. ->select($select)
  232. ->from(self::tableName() . ' l')
  233. ->innerJoin(OperaStation::tableName() . ' s', 'l.line_id = s.line_id')
  234. ->where($where)
  235. ->asArray()
  236. ->all();
  237. return $res;
  238. }
  239. /**
  240. * Function Description:检查线路
  241. * Function Name: checkLine
  242. * @param $line_code
  243. * @param $line_id
  244. *
  245. * @return array|\yii\db\ActiveRecord[]
  246. *
  247. * @author 李健
  248. */
  249. public function checkLine($line_code, $line_id)
  250. {
  251. $select = [
  252. 'line_id'
  253. ];
  254. $where = ['and'];
  255. $where[] = ['=', 'cancel_flag', 0];
  256. $where[] = ['=', 'line_code', $line_code];
  257. $where[] = ['!=', 'line_id', $line_id];
  258. $res = self::find()->select($select)->from(self::tableName())->where($where)->asArray()->all();
  259. return $res;
  260. }
  261. public function uptInfo($line_id, $user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_select_seat, $remark = '', $run_duty_id)
  262. {
  263. try {
  264. $obj = self::findOne($line_id);
  265. $obj->UPDATE_USER_ID = $user_id;
  266. $obj->LINE_NAME = $line_name;
  267. $obj->LINE_CODE = $line_code;
  268. $obj->LINE_TYPE = $line_type;
  269. $obj->LINE_SUB_TYPE = $line_sub_type;
  270. $obj->SALE_EXPIRED_TYPE = $time_type;
  271. $obj->SALE_EXPIRED_TIME = $time_info;
  272. $obj->ORG_ID = $supply_id;
  273. $obj->MAIN_CORP_ID = $main_corp_id;
  274. $obj->ALLOW_SELECT_SEAT = $allow_select_seat;
  275. $obj->RUN_DUTY_ID = $run_duty_id;
  276. $obj->REMARK = $remark;
  277. return $obj->save();
  278. } catch (Exception $e) {
  279. return false;
  280. }
  281. }
  282. /**
  283. * Des:获取线路信息
  284. * Name: getLineInfo
  285. * @param $line_id
  286. * @return array|null|\yii\db\ActiveRecord
  287. * @author 倪宗锋
  288. */
  289. public function getLineInfo($line_id){
  290. $select = [
  291. 'timeExpendMinutes' => new Expression('(MAX(START_MINUTES) - MIN(START_MINUTES))'),
  292. 'distance' => new Expression("SUM(DISTANCE)"),
  293. 'bottomPrice' => new Expression("((SELECT MIN(PROD_PRICE) from opera_tickets where LINE_ID = a.LINE_ID and CANCEL_FLAG=0))"),
  294. 'desc' => 'a.REMARK',
  295. 'name' => 'a.line_name'
  296. ];
  297. $where = [
  298. 'and',
  299. ['=','a.LINE_ID',$line_id],
  300. ['=','b.LINE_ID',$line_id],
  301. ['=','a.CANCEL_FLAG',0],
  302. ['=','b.CANCEL_FLAG',0]
  303. ];
  304. $getInfo = self::find()->select($select)
  305. ->from(self::tableName().' a')
  306. ->innerJoin(OperaStation::tableName().' b','a.LINE_ID = b.LINE_ID ')
  307. ->where($where)
  308. ->asArray()
  309. ->one();
  310. return $getInfo;
  311. }
  312. public function getOperaLineTicketsFromLine( $line_id, $fromCityId, $toCityId ) {
  313. $select = [
  314. "fromStationCode" => "START_STATION_RES_ID",
  315. "toStationCode" => "END_STATION_RES_ID",
  316. "price" => "PROD_PRICE"
  317. ];
  318. $where = [
  319. 'and',
  320. ['=', 'LINE_ID', $line_id],
  321. ['=','CANCEL_FLAG',0],
  322. ['=','IS_ONSALE',1],
  323. ['=','START_STATION_AREA_ID',$fromCityId],
  324. ['=','END_STATION_AREA_ID',$toCityId],
  325. ];
  326. $getInfo = self::find()->select($select)
  327. ->from(OperaTickets::tableName())
  328. ->where($where)
  329. ->asArray()
  330. ->all();
  331. return $getInfo;
  332. }
  333. }