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.
 
 
 
 
 
 

290 wiersze
9.8 KiB

  1. <?php
  2. /**
  3. * 数据库表类 bus_ticket
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/15 14:22 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. use yii\db\Expression;
  18. /**
  19. * 数据库表类 bus_ticket.
  20. * @property integer $ticket_id
  21. * @property integer $start_area_id
  22. * @property string $start_area_name
  23. * @property integer $end_area_id
  24. * @property string $end_area_name
  25. * @property integer $start_res_id
  26. * @property string $start_res_name
  27. * @property integer $end_res_id
  28. * @property string $end_res_name
  29. * @property integer $line_id
  30. * @property integer $line_type
  31. * @property string $prod_price
  32. * @property string $line_name
  33. * @property double $start_res_longitude
  34. * @property double $start_res_latitude
  35. * @property double $end_res_longitude
  36. * @property double $end_res_latitude
  37. */
  38. class BusTicket extends ActiveRecord
  39. {
  40. /**
  41. * @inheritdoc
  42. */
  43. public static function tableName()
  44. {
  45. return 'bus_ticket';
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function rules()
  51. {
  52. return [
  53. [['ticket_id'], 'required'],
  54. [['ticket_id', 'start_area_id', 'end_area_id', 'start_res_id', 'end_res_id', 'line_id', 'line_type'], 'integer'],
  55. [['prod_price', 'start_res_longitude', 'start_res_latitude', 'end_res_longitude', 'end_res_latitude'], 'number'],
  56. [['start_area_name', 'end_area_name', 'start_res_name', 'end_res_name'], 'string', 'max' => 50],
  57. [['line_name'], 'string', 'max' => 255],
  58. [['ticket_id'], 'unique'],
  59. ];
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function attributeLabels()
  65. {
  66. return [
  67. 'ticket_id' => 'Ticket ID',
  68. 'start_area_id' => 'Start Area ID',
  69. 'start_area_name' => 'Start Area Name',
  70. 'end_area_id' => 'End Area ID',
  71. 'end_area_name' => 'End Area Name',
  72. 'start_res_id' => 'Start Res ID',
  73. 'start_res_name' => 'Start Res Name',
  74. 'end_res_id' => 'End Res ID',
  75. 'end_res_name' => 'End Res Name',
  76. 'line_id' => 'Line ID',
  77. 'line_type' => 'Line Type',
  78. 'prod_price' => 'Prod Price',
  79. 'line_name' => 'Line Name',
  80. 'start_res_longitude' => 'Start Res Longitude',
  81. 'start_res_latitude' => 'Start Res Latitude',
  82. 'end_res_longitude' => 'End Res Longitude',
  83. 'end_res_latitude' => 'End Res Latitude',
  84. ];
  85. }
  86. /**
  87. * Function Description:查返程票种id对应的产品id
  88. * Function Name: getBackTicketId
  89. * @param $ticket_id
  90. *
  91. * @return mixed
  92. *
  93. * @author 娄梦宁
  94. */
  95. public function getBackTicketId($ticket_id)
  96. {
  97. $result = self::find()->select(['c.pro_cate_id'])
  98. ->from(self::tableName() . ' as a')
  99. ->innerJoin('bus_ticket b', 'a.end_res_name=b.start_res_name and a.start_res_name=b.end_res_name')
  100. ->leftJoin('prod_category c', 'a.ticket_id=c.bus_ticket_id')
  101. ->where(['b.ticket_id' => $ticket_id])
  102. ->groupBy('a.ticket_id')
  103. ->asArray()
  104. ->one();
  105. return $result['pro_cate_id'];
  106. }
  107. /*
  108. * 获取当前数据库所存票种信息
  109. */
  110. public function getBusArr()
  111. {
  112. $result = self::find()
  113. ->from(self::tableName())
  114. ->indexBy('ticket_id')
  115. ->asArray()
  116. ->all();
  117. return $result;
  118. }
  119. /**
  120. * Des:根据票种ID获取所有票种的上下车站点信息
  121. * 如果用户选择了上下车poi则进行过滤 只获取这些poi对应的票种
  122. * Name: getTicketAndLineByIDs
  123. * @param $ticketIds array
  124. * @param $params array
  125. * @return array
  126. * @author 倪宗锋
  127. */
  128. public function getTicketAndLineByIDs($ticketIds, $params)
  129. {
  130. $where = [
  131. 'and',
  132. ['in', 'ticket_id', $ticketIds],
  133. ['=', 'b.delete_flag', 0]
  134. ];
  135. if (empty($params['start_poi']) == false && empty($params['end_poi']) == false) {
  136. if ($params['if_back']) {
  137. $where[] = ['=', 'a.start_area_id', $params['end_poi']];
  138. $where[] = ['=', 'a.end_area_id', $params['start_poi']];
  139. } else{
  140. $where[] = ['=', 'a.start_area_id', $params['start_poi']];
  141. $where[] = ['=', 'a.end_area_id', $params['end_poi']];
  142. }
  143. }
  144. $result = self::find()->select(['a.start_res_name', 'a.start_res_id', new Expression("GROUP_CONCAT(CONCAT(ticket_id,'|',a.end_res_id,'|',a.end_res_name,'|',b.pro_cate_id) separator '||') FxTicket")])
  145. ->from(self::tableName() . ' as a')
  146. ->innerJoin(ProdCategory::tableName() . ' b', 'a.ticket_id = b.bus_ticket_id and b.sign is null')
  147. ->where($where)
  148. ->groupBy('a.start_res_id')
  149. ->indexBy('start_res_id')
  150. ->asArray()
  151. ->all();
  152. if (empty($result)) {
  153. return [];
  154. }
  155. foreach ($result as $key => $val) {//拼接成以起始站为中心的数组
  156. $result[$key]['end_station_list'] = [];
  157. $ticketArr = explode('||', $val['FxTicket']);
  158. foreach ($ticketArr as $val1) {
  159. $theArr = explode('|', $val1);
  160. if (count($theArr) == 4) {
  161. $theArr1['ticket_id'] = $theArr[0];
  162. $theArr1['end_res_id'] = $theArr[1];
  163. $theArr1['end_res_name'] = $theArr[2];
  164. $theArr1['pro_cate_id'] = $theArr[3];
  165. $result[$key]['end_station_list'][$theArr[0]] = $theArr1;
  166. }
  167. }
  168. unset($result[$key]['FxTicket']);
  169. }
  170. return $result;
  171. }
  172. /**
  173. * Des: 获取出发站点
  174. * Name: getStartStation
  175. * @param $param
  176. * @return array
  177. * @author 倪宗锋
  178. */
  179. public function getStartStation($param)
  180. {
  181. //where条件
  182. $where = ['and'];
  183. $where[] = ['=', 'c.system', $param['system']];
  184. if (empty($param['station_id']) == false) {
  185. $where[] = ['=', 'a.end_area_id', $param['station_id']];
  186. }
  187. if (empty($param['poi_type']) == false) {
  188. $where[] = ['like', 'y.POI_TYPE2', "{{$param['poi_type']}}"];
  189. }
  190. if (empty($param['poi_name']) == false) {
  191. $where[] = ['like', 'a.start_area_name', "{$param['poi_name']}"];
  192. }
  193. if (empty($param['category_id']) == false) {
  194. $where[] = ['=', 'c.cms_cate_id', $param['category_id']];
  195. }
  196. if (empty($param['limit'])) {
  197. $param['limit'] = 999;
  198. }
  199. //select 条件
  200. $select = [
  201. 'id' => 'a.start_area_id',
  202. 'name' => 'a.start_area_name'
  203. ];
  204. $result = self::find()->select($select)
  205. ->from(self::tableName() . ' a')
  206. ->distinct()
  207. ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign')
  208. ->innerJoin(CmsCategoryProd::tableName() . ' c', 'b.pro_cate_id = c.prod_cate_id')
  209. ->innerJoin(BaseArea::tableName() . ' y', 'a.start_area_id = y.ID')
  210. ->orderBy('b.sales_count desc ')
  211. ->limit($param['limit'])
  212. ->where($where)
  213. ->asArray()
  214. ->all();
  215. return $result;
  216. }
  217. /**
  218. * Des:获取目的地的station
  219. * Name: getEndStation
  220. * @param $param
  221. * @return array
  222. * @author 倪宗锋
  223. */
  224. public function getEndStation($param)
  225. {
  226. //where条件
  227. $where = ['and'];
  228. $where[] = ['=', 'c.system', $param['system']];
  229. if (empty($param['station_id']) == false) {
  230. $where[] = ['=', 'a.start_area_id', $param['station_id']];
  231. }
  232. if (empty($param['poi_type']) == false) {
  233. $where[] = ['like', 'y.POI_TYPE2', "{{$param['poi_type']}}"];
  234. }
  235. if (empty($param['poi_name']) == false) {
  236. $where[] = ['like', 'a.end_area_name', "{$param['poi_name']}"];
  237. }
  238. if (empty($param['category_id']) == false) {
  239. $where[] = ['=', 'c.cms_cate_id', $param['category_id']];
  240. }
  241. if (empty($param['limit'])) {
  242. $param['limit'] = 999;
  243. }
  244. //select 条件
  245. $select = [
  246. 'id' => 'a.end_area_id',
  247. 'name' => 'a.end_area_name'
  248. ];
  249. $result = self::find()->select($select)
  250. ->distinct()
  251. ->from(self::tableName() . ' a')
  252. ->innerJoin(ProdCategory::tableName() . ' b', 'a.line_id = b.sign')
  253. ->innerJoin(CmsCategoryProd::tableName() . ' c', 'b.pro_cate_id = c.prod_cate_id')
  254. ->innerJoin(BaseArea::tableName() . ' y', 'a.end_area_id = y.ID')
  255. ->orderBy('b.sales_count desc ')
  256. ->limit($param['limit'])
  257. ->where($where)
  258. ->asArray()
  259. ->all();
  260. return $result;
  261. }
  262. /**
  263. * Function Description:获取所有目的地poi数组
  264. * Function Name: getAllArea
  265. *
  266. * @return array|ActiveRecord[]
  267. *
  268. * @author 娄梦宁
  269. */
  270. public function getAllArea(){
  271. $result=self::find()->select('end_area_id as area_id,end_area_name as area_name')
  272. ->from(self::tableName())
  273. ->distinct()
  274. ->asArray()
  275. ->all();
  276. return $result;
  277. }
  278. }