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.
 
 
 
 
 
 

365 lines
12 KiB

  1. <?php
  2. /**
  3. * 数据库表类 order_travel
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/28 14:12 $
  14. */
  15. namespace common\models;
  16. use Yii;
  17. use common\util\Util;
  18. use yii\base\Exception;
  19. use yii\db\ActiveRecord;
  20. use yii\db\Expression;
  21. /**
  22. * 数据库表类 order_travel.
  23. * @property integer $travel_id
  24. * @property string $start_time
  25. * @property string $end_time
  26. * @property integer $u_id
  27. * @property integer $order_id
  28. * @property integer $cs_order_id
  29. * @property integer $prod_id
  30. * @property integer $start_res_id
  31. * @property string $start_res
  32. * @property integer $end_res_id
  33. * @property string $end_res
  34. */
  35. class OrderTravel extends ActiveRecord
  36. {
  37. /**
  38. * @inheritdoc
  39. */
  40. public static function tableName()
  41. {
  42. return 'order_travel';
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['start_time', 'end_time', 'u_id', 'cs_order_id'], 'required'],
  51. [['start_time', 'end_time'], 'safe'],
  52. [['u_id', 'cs_order_id', 'start_res_id', 'end_res_id'], 'integer'],
  53. [['start_longitude', 'start_latitude'], 'number'],
  54. [['prod_id', 'start_res', 'end_res', 'start_area_name', 'end_area_name'], 'string', 'max' => 255],
  55. [['contacts_name', 'contacts_phone', 'contacts_ID'], 'string', 'max' => 120],
  56. ];
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'travel_id' => 'Travel ID',
  65. 'start_time' => 'Start Time',
  66. 'end_time' => 'End Time',
  67. 'u_id' => 'U ID',
  68. 'cs_order_id' => 'Cs Order ID',
  69. 'prod_id' => 'Prod ID',
  70. 'start_res_id' => 'Start Res ID',
  71. 'start_res' => 'Start Res',
  72. 'end_res_id' => 'End Res ID',
  73. 'end_res' => 'End Res',
  74. 'start_area_name' => 'Start Area Name',
  75. 'end_area_name' => 'End Area Name',
  76. 'start_longitude' => 'Start Longitude',
  77. 'start_latitude' => 'Start Latitude',
  78. 'contacts_name' => 'Contacts Name',
  79. 'contacts_phone' => 'Contacts Phone',
  80. 'contacts_ID' => 'Contacts ID',
  81. ];
  82. }
  83. /**
  84. * Des:根据travel_id获取详情
  85. * Name: getInfoByTravelId
  86. * @param $param
  87. * @return array
  88. * @author 孙彤
  89. */
  90. public function getInfoByTravelId($param)
  91. {
  92. $select = [
  93. 'start_date' => new Expression('DATE(start_time)'),//出发日期
  94. 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
  95. 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间 时分
  96. 'start_time_s' => new Expression("DATE_FORMAT(start_time,'%H:%i:%s')"),//出发时间 时分秒
  97. 'travel_id',
  98. 'end_time',
  99. 'u_id',
  100. 'prod_id',
  101. 'cs_order_id',
  102. 'start_res_id',
  103. 'end_res_id',
  104. 'end_res',
  105. 'start_res',
  106. 'start_area_name',
  107. 'end_area_name',
  108. 'start_longitude',
  109. 'start_latitude',
  110. 'contacts_name',
  111. 'contacts_phone',
  112. 'contacts_ID',
  113. 'start_time_all' => 'start_time'
  114. ];
  115. $where = ['=', 'travel_id', $param['travel_id']];
  116. $info = self::find()->select($select)
  117. ->where($where)
  118. ->asArray()
  119. ->one();
  120. if (empty($info['travel_id'])) {
  121. return [];
  122. }
  123. return $info;
  124. }
  125. /**
  126. * Des:获取用户的行程列表
  127. * Name: getUserTravelList
  128. * @param $param
  129. * @return array
  130. * @author 倪宗锋
  131. */
  132. public function getUserTravelList($param)
  133. {
  134. $siteConfig = Util::getSiteConfig();
  135. $codeUrl = $siteConfig['fx_host'] . "/fx/?r=weChat/we-chat/q-code&qCode=";
  136. $select = [
  137. 'a.travel_id',//ID
  138. 'start_date' => new Expression('DATE(a.start_time)'),//出发日期
  139. 'if_today' => new Expression('if(date(a.start_time)=DATE(NOW()),1,0)'),//是否今天
  140. 'start_time' => new Expression("DATE_FORMAT(a.start_time,'%H:%i')"),//出发时间
  141. 'status_des' => new Expression("case 1
  142. WHEN NOW() <= a.start_time THEN '待出行'
  143. WHEN NOW() > a.start_time and NOW()< a.end_time THEN '进行中'
  144. ELSE '已完成'
  145. END"
  146. ),
  147. 'status_id' => new Expression("case 1
  148. WHEN NOW() <= a.start_time THEN 1
  149. WHEN NOW() > a.start_time and NOW()< a.end_time THEN 2
  150. ELSE 3
  151. END"
  152. ),
  153. 'a.cs_order_id',
  154. 'code_url' => new Expression("concat('{$codeUrl}','',a.cs_order_id)"),
  155. 'if_comment' => new Expression("if(b.travel_id is NULL, 0, 1)"),
  156. 'a.start_area_name',
  157. 'a.end_area_name',
  158. 'a.end_res',
  159. 'a.start_res',
  160. 'a.prod_id',
  161. 'start_time_all' => 'start_time'
  162. ];
  163. $where = ['and'];
  164. $where[] = ['=', 'a.u_id', $param['u_id']];
  165. if ($param['status_id'] == 3) {
  166. $where[] = ['>=', 'now()', new Expression('a.end_time')];
  167. $order = 'a.start_time desc,a.travel_id';
  168. } else {
  169. $where[] = ['<', 'now()', new Expression('a.end_time')];
  170. $order = 'a.start_time,a.travel_id';
  171. }
  172. $offset = ($param['current_page'] - 1) * $param['page_size'];
  173. $list = self::find()->select($select)
  174. ->from(self::tableName() . ' a')
  175. ->leftJoin(ProdComment::tableName() . ' b', 'a.travel_id =b.travel_id')
  176. ->where($where)
  177. ->limit($param['page_size'])
  178. ->offset($offset)
  179. ->orderBy($order)
  180. ->asArray()
  181. ->all();
  182. if (empty($list['0'])) {
  183. return [];
  184. }
  185. return $list;
  186. }
  187. /**
  188. * Des:获取用户行程ID
  189. * Name: getUserAllTravel
  190. * @param $u_id
  191. * @return array|ActiveRecord[]
  192. * @author 倪宗锋
  193. */
  194. public function getUserAllTravelId($u_id)
  195. {
  196. $select = [
  197. 'travel_id',
  198. 'cs_order_id'
  199. ];
  200. $where = ['=', 'u_id', $u_id];
  201. $list = self::find()->select($select)
  202. ->where($where)
  203. ->indexBy('cs_order_id')
  204. ->orderBy('start_time desc')
  205. ->asArray()
  206. ->all();
  207. if (empty($list)) {
  208. return [];
  209. }
  210. return $list;
  211. }
  212. /**
  213. * Des:删除旧数据
  214. * Name: delByIds
  215. * @param $del
  216. * @param $u_id
  217. * @return array
  218. * @author 倪宗锋
  219. */
  220. public function delByIds($del, $u_id)
  221. {
  222. if (empty($del)) {
  223. return Util::returnArrSu();
  224. }
  225. $where = [
  226. 'and',
  227. ['in', 'cs_order_id', $del],
  228. ['=', 'u_id', $u_id]
  229. ];
  230. $tab = clone $this;
  231. $int = $tab::deleteAll($where);
  232. if (empty($int)) {
  233. return Util::returnArrEr('删除旧数据失败!');
  234. }
  235. return Util::returnArrSu();
  236. }
  237. /**
  238. * Des:添加记录
  239. * Name: addNews
  240. * @param $new
  241. * @param $u_id
  242. * @return array
  243. * @author 倪宗锋
  244. */
  245. public function addNews($new, $u_id)
  246. {
  247. $orderMain = new OrderMain();
  248. $flag = true;
  249. foreach ($new as $val) {
  250. $transaction = Yii::$app->db->beginTransaction();
  251. try {
  252. $getProdId = $orderMain->getProdIdByCsOrderId($val['cs_order_id']);
  253. /**插入行程表*/
  254. $data = [
  255. 'start_time' => date('Y-m-d H:i:s', strtotime($val['start_time'])),
  256. 'end_time' => date('Y-m-d H:i:s', strtotime($val['end_time'])),
  257. 'u_id' => $u_id,
  258. 'cs_order_id' => $val['cs_order_id'],
  259. 'prod_id' => $getProdId,
  260. 'start_res_id' => $val['start_res_id'],
  261. 'start_res' => $val['start_res'],
  262. 'end_res_id' => $val['end_res_id'],
  263. 'end_res' => trim($val['end_res']),
  264. 'start_area_name' => trim($val['start_area_name']),
  265. 'end_area_name' => trim($val['end_area_name']),
  266. 'start_longitude' => trim($val['start_longitude']),
  267. 'start_latitude' => trim($val['start_latitude']),
  268. 'contacts_name' => trim($val['customer_name']),
  269. 'contacts_phone' => trim($val['customer_mobile']),
  270. 'contacts_ID' => trim($val['customer_id_no']),
  271. ];
  272. $clone=clone $this;
  273. $clone->isNewRecord = true;
  274. $clone->setAttributes($data);
  275. $res = $clone->save(false);
  276. if ($res === false) {
  277. $flag = false;
  278. $transaction->rollBack();
  279. continue;
  280. }
  281. $transaction->commit();
  282. } catch (Exception $e) {
  283. $flag = false;
  284. $transaction->rollBack();
  285. continue;
  286. }
  287. }
  288. if ($flag == false) {
  289. return Util::returnArrEr('新增异常!');
  290. }
  291. return Util::returnArrSu();
  292. }
  293. /**
  294. * Des:添加虚拟记录
  295. * Name: addNews
  296. * @param $new
  297. * @param $u_id
  298. * @return array
  299. * @author
  300. */
  301. public function getInfoByTravelOne($param)
  302. {
  303. $select = [
  304. 'start_date' => new Expression('DATE(start_time)'),//出发日期
  305. 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
  306. 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间
  307. 'travel_id',
  308. 'end_time',
  309. 'u_id',
  310. 'prod_id',
  311. 'cs_order_id',
  312. 'start_res_id',
  313. 'end_res_id',
  314. 'end_res',
  315. 'start_res',
  316. 'start_area_name',
  317. 'end_area_name',
  318. 'start_longitude',
  319. 'start_latitude',
  320. 'contacts_name',
  321. 'contacts_phone',
  322. 'contacts_ID',
  323. ];
  324. }
  325. public function getInfoByTravel($param)
  326. {
  327. $select = [
  328. 'start_date' => new Expression('DATE(start_time)'),//出发日期
  329. 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
  330. 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间
  331. 'travel_id',
  332. 'end_time',
  333. 'u_id',
  334. 'prod_id',
  335. 'cs_order_id',
  336. 'start_res_id',
  337. 'end_res_id',
  338. 'end_res',
  339. 'start_res',
  340. 'start_area_name',
  341. 'end_area_name',
  342. 'start_longitude',
  343. 'start_latitude',
  344. 'contacts_name',
  345. 'contacts_phone',
  346. 'contacts_ID',
  347. ];
  348. }
  349. }