您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

282 行
10 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. /**
  6. * This is the model class for table "base_tailor_station".
  7. *
  8. * @property integer $id
  9. * @property integer $person_num
  10. * @property string $run_date
  11. * @property string $run_minutes
  12. * @property integer $baggage_weight
  13. * @property string $address
  14. * @property string $lng
  15. * @property string $lat
  16. * @property integer $tailor_type
  17. * @property string $flight_number
  18. * @property integer $area_name
  19. * @property integer $poi_type1
  20. * @property string $poi_type2
  21. * @property integer $inout_type
  22. * @property string $line_id
  23. * @property string $name
  24. * @property string $tel
  25. * @property string $id_card
  26. * @property string $memo
  27. * @property string create_time
  28. * @property string update_time
  29. * @property string create_user_id
  30. * @property string update_user_id
  31. * @property integer main_corp_id
  32. * @property integer address_res_id
  33. * @property integer product_res_id
  34. * @property integer product_id
  35. * @property integer original_order_id
  36. * @property integer org_id
  37. * @property integer org_no
  38. * @property integer order_id
  39. */
  40. class BaseTailorStation extends \yii\db\ActiveRecord
  41. {
  42. /**
  43. * @inheritdoc
  44. */
  45. public static function tableName()
  46. {
  47. return 'base_tailor_station';
  48. }
  49. // public function load($data, $formName = null)
  50. // {
  51. // //当前用户所属运营主体
  52. // $base_user = new BaseUser();
  53. // $user_main_corp = $base_user->getMainCorp();
  54. // $user_id = Yii::$app->request->cookies->getValue('user_id');
  55. // if ($this->isNewRecord) {
  56. // $this->create_time = date('Y-m-d H:i:s');
  57. // $this->create_user_id = $user_id;
  58. // }
  59. // $this->update_time = date('Y-m-d H:i:s');
  60. // $this->update_user_id = $user_id;
  61. // $this->main_corp_id = $user_main_corp;
  62. // return parent::load($data, $formName); // TODO: Change the autogenerated stub
  63. // }
  64. /**
  65. * @inheritdoc
  66. */
  67. public function rules()
  68. {
  69. return [
  70. [['id', 'person_num', 'baggage_weight', 'tailor_type', 'poi_type1', 'inout_type', 'cancel_flag', 'address_res_id', 'product_res_id', 'product_id', 'original_order_id', 'org_id'], 'integer'],
  71. [['name', 'tel', 'person_num', 'run_date', 'address', 'lng', 'lat', 'tailor_type', 'area_name', 'poi_type1', 'poi_type2', 'inout_type', 'product_id', 'product_res_id', 'org_id'], 'required'],
  72. [['flight_number', 'id_card', 'memo', 'baggage_weight', 'update_time', 'create_time', 'create_user_id', 'update_user_id', 'line_id', 'main_corp_id', 'original_order_id', 'org_no', 'order_id'], 'safe'],
  73. [['run_date'], 'string', 'max' => 10],
  74. [['run_minutes'], 'string', 'max' => 5],
  75. [['address', 'org_no'], 'string', 'max' => 500],
  76. [['lng', 'lat', 'flight_number', 'poi_type2'], 'string', 'max' => 50],
  77. // [['line_id'], 'string', 'max' => 100],
  78. [['id'], 'unique'],
  79. //默认值
  80. [['poi_type1'], 'default', 'value' => '402'],
  81. [['poi_type2'], 'default', 'value' => '0'],
  82. [['inout_type'], 'default', 'value' => '0'],
  83. [['cancel_flag'], 'default', 'value' => '0'],
  84. //手机限制
  85. ['tel', 'number'],
  86. ['tel', 'string', 'min' => 11],
  87. ['tel', 'filter', 'filter' => 'trim'],
  88. //身份证限制
  89. ['id_card', 'string', 'min' => 15],
  90. ];
  91. }
  92. /**
  93. * @inheritdoc
  94. */
  95. public function attributeLabels()
  96. {
  97. return [
  98. 'id' => 'id',
  99. 'person_num' => '人数',
  100. 'run_date' => '上车日期',
  101. 'run_minutes' => '上车时间',
  102. 'baggage_weight' => '行李重量',
  103. 'address' => '地址',
  104. 'lng' => '经度',
  105. 'lat' => '纬度',
  106. 'tailor_type' => '产品类型',
  107. 'flight_number' => '航班号',
  108. 'area_name' => '所属区域 对应base_area.area_name',
  109. 'poi_type1' => '站点类别 对应base_area.poi_type1 401区域 402站点',
  110. 'poi_type2' => '站点类型 对应base_area.poi_type2 404 至412',
  111. 'inout_type' => '上下车属性ID,DICT_TYPE.ID,108上,109上下,110下。非0,必选',
  112. // 'line_id' => '若未成线路则为 null 成了线路则 线路id以逗号拼接',
  113. 'dict_type.TYPE_NAME' => '产品类型',
  114. 'name' => '顾客姓名',
  115. 'tel' => '顾客电话',
  116. 'id_card' => '身份证',
  117. 'memo' => '备注',
  118. 'product_id' => '产品名称',
  119. 'product_res_id' => '上下车站点',
  120. 'original_order_id' => '原订单号',
  121. 'org_id' => '渠道商',
  122. 'org_no' => '渠道号',
  123. 'line_id' => '线路id',
  124. 'order_id' => '订单号',
  125. ];
  126. }
  127. public function getdict_type()
  128. {
  129. return $this->hasOne(DictType::className(), ['ID' => 'tailor_type']);
  130. }
  131. public function getopera_tailor_product()
  132. {
  133. return $this->hasOne(OperaTailorProduct::className(), ['id' => 'product_id']);
  134. }
  135. public function getopera_line()
  136. {
  137. return $this->hasOne(OperaLine::className(), ['LINE_ID' => 'line_id']);
  138. }
  139. /**
  140. * Function Description:获取站点列表
  141. * Function Name: getIndex
  142. *
  143. *
  144. * @author LUOCJ
  145. */
  146. // public function getIndex($data)
  147. // {
  148. // //当前用户所属运营主体
  149. // $base_user = new BaseUser();
  150. // $user_main_corp = $base_user->getMainCorp();
  151. // $query = self::find()->where(['and', ['=', 'cancel_flag', 0]])->orderBy('`create_time` desc');
  152. // $dataProvider = new ActiveDataProvider([
  153. // 'query' => $query,
  154. // ]);
  155. // $query->andFilterWhere(['=', 'main_corp_id', $user_main_corp]);
  156. // if (isset($data['address']))
  157. // $query->andFilterWhere(['like', 'address', $data['address']]);
  158. // if (isset($data['run_date']))
  159. // $query->andFilterWhere(['=', 'run_date', $data['run_date']]);
  160. // if (isset($data['name']))
  161. // $query->andFilterWhere(['like', 'name', $data['name']]);
  162. // if (isset($data['tel']))
  163. // $query->andFilterWhere(['like', 'tel', $data['tel']]);
  164. // return $dataProvider;
  165. // }
  166. /**
  167. * Function Description:获取所有点参数
  168. * Function Name: getPointInfo
  169. *
  170. * @return string
  171. *
  172. * @author LUOCJ
  173. */
  174. public function getPointInfo($product_id, $run_date)
  175. {
  176. $query = self::find()->where(['and', ['=', 'cancel_flag', 0], ['=', 'run_date', $run_date], ['=', 'product_id', $product_id], ['=', 'line_id', '']])->asArray()->all();
  177. $sql = "select a.inout_type,a.product_id,b.TYPE_ID as type_id,b.PROPERTY as property,a.res_id,c.RES_NAME as res_name,d.area_name from opera_tailor_product_station a inner join base_area d on a.area_id = d.ID inner join base_resource c on a.res_id = c.RES_ID left join base_resource_property b on a.res_id = b.RES_ID and b.TYPE_ID in (212,213) and a.product_id ={$product_id} and a.cancel_flag=0";
  178. $query_station = Yii::$app->db->createCommand($sql)->queryAll();
  179. $tp_station = [];
  180. foreach ($query_station as $k => $v) {
  181. if ($v['type_id'] == 212)
  182. $tp_station[$v['res_id']]['lng'] = $v['property'];
  183. elseif ($v['type_id'] == 213) {
  184. $tp_station[$v['res_id']]['lat'] = $v['property'];
  185. $tp_station[$v['res_id']]['res_name'] = $v['res_name'];
  186. $tp_station[$v['res_id']]['area_name'] = $v['area_name'];
  187. $tp_station[$v['res_id']]['inout_type'] = $v['inout_type'];
  188. }
  189. }
  190. $fin_station = [];
  191. foreach ($tp_station as $k => $v) {
  192. $fin_station[$k]['id'] = 0;
  193. $fin_station[$k]['name'] = '';
  194. $fin_station[$k]['tel'] = '';
  195. $fin_station[$k]['person_num'] = '';
  196. $fin_station[$k]['address'] = $v['res_name'];
  197. $fin_station[$k]['area_name'] = $v['area_name'];
  198. $fin_station[$k]['res_id'] = $k;
  199. $fin_station[$k]['lng'] = $v['lng'];
  200. $fin_station[$k]['lat'] = $v['lat'];
  201. $fin_station[$k]['tailor_type'] = $v['inout_type'] == 110 ? 701 : 702;
  202. }
  203. $fin_station = array_values($fin_station);
  204. $res = array_merge($query, $fin_station);
  205. return json_encode($res);
  206. }
  207. /**
  208. * Function Description:根据动态巴士线路id,获取出发日期
  209. * Function Name: getDynamicRunDate
  210. * @param $line_id
  211. *
  212. * @return string
  213. *
  214. * @author 温依莅
  215. */
  216. public static function getDynamicRunDate($line_id)
  217. {
  218. $res = self::find()->select(
  219. ['id', 'line_id', 'run_date']
  220. )->where([
  221. 'line_id' => $line_id,
  222. 'cancel_flag' => 0
  223. ])->limit(1)->asArray()->one();
  224. return $res['run_date'];
  225. }
  226. /**
  227. * Function Description:获取动态巴士线路班次的人数
  228. * Function Name: getTotalNum
  229. * @param int $line_id 线路id
  230. *
  231. * @return int
  232. *
  233. * @author 温依莅
  234. */
  235. public static function getTotalNum($line_id)
  236. {
  237. $res = self::find()
  238. ->where([
  239. 'line_id' => $line_id,
  240. 'cancel_flag' => 0
  241. ])->sum('person_num');
  242. return $res;
  243. }
  244. /**
  245. * Function Description:获取某线路的乘客信息
  246. * Function Name: getCustomerInfo
  247. * @param int $line_id 线路id
  248. * @param int $main_corp_id 运营主体id
  249. * @return array
  250. *
  251. * @author 温依莅
  252. */
  253. public static function getDynamicCustomerInfo($line_id, $main_corp_id)
  254. {
  255. $res = self::find()->select([
  256. 'address','id', 'name', 'tel', 'id_card', 'memo', 'person_num', 'run_date', 'main_corp_id', 'tailor_type', 'inout_type', 'address_res_id', 'product_res_id', 'product_id', 'org_id', 'org_no', 'original_order_id'
  257. ])->where([
  258. 'line_id' => $line_id,
  259. 'main_corp_id' => $main_corp_id,
  260. 'cancel_flag' => 0
  261. ])->asArray()->all();
  262. return $res;
  263. }
  264. }