|
- <?php
- /**
- * 数据库表类 order_travel
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/06/28 14:12 $
- */
-
- namespace common\models;
-
- use Yii;
- use common\util\Util;
- use yii\base\Exception;
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * 数据库表类 order_travel.
- * @property integer $travel_id
- * @property string $start_time
- * @property string $end_time
- * @property integer $u_id
- * @property integer $order_id
- * @property integer $cs_order_id
- * @property integer $prod_id
- * @property integer $start_res_id
- * @property string $start_res
- * @property integer $end_res_id
- * @property string $end_res
- */
- class OrderTravel extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'order_travel';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['start_time', 'end_time', 'u_id', 'cs_order_id'], 'required'],
- [['start_time', 'end_time'], 'safe'],
- [['u_id', 'cs_order_id', 'start_res_id', 'end_res_id'], 'integer'],
- [['start_longitude', 'start_latitude'], 'number'],
- [['prod_id', 'start_res', 'end_res', 'start_area_name', 'end_area_name'], 'string', 'max' => 255],
- [['contacts_name', 'contacts_phone', 'contacts_ID'], 'string', 'max' => 120],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'travel_id' => 'Travel ID',
- 'start_time' => 'Start Time',
- 'end_time' => 'End Time',
- 'u_id' => 'U ID',
- 'cs_order_id' => 'Cs Order ID',
- 'prod_id' => 'Prod ID',
- 'start_res_id' => 'Start Res ID',
- 'start_res' => 'Start Res',
- 'end_res_id' => 'End Res ID',
- 'end_res' => 'End Res',
- 'start_area_name' => 'Start Area Name',
- 'end_area_name' => 'End Area Name',
- 'start_longitude' => 'Start Longitude',
- 'start_latitude' => 'Start Latitude',
- 'contacts_name' => 'Contacts Name',
- 'contacts_phone' => 'Contacts Phone',
- 'contacts_ID' => 'Contacts ID',
- ];
- }
-
- /**
- * Des:根据travel_id获取详情
- * Name: getInfoByTravelId
- * @param $param
- * @return array
- * @author 孙彤
- */
- public function getInfoByTravelId($param)
- {
- $select = [
- 'start_date' => new Expression('DATE(start_time)'),//出发日期
- 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
- 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间 时分
- 'start_time_s' => new Expression("DATE_FORMAT(start_time,'%H:%i:%s')"),//出发时间 时分秒
- 'travel_id',
- 'end_time',
- 'u_id',
- 'prod_id',
- 'cs_order_id',
- 'start_res_id',
- 'end_res_id',
- 'end_res',
- 'start_res',
- 'start_area_name',
- 'end_area_name',
- 'start_longitude',
- 'start_latitude',
- 'contacts_name',
- 'contacts_phone',
- 'contacts_ID',
- 'start_time_all' => 'start_time'
- ];
- $where = ['=', 'travel_id', $param['travel_id']];
- $info = self::find()->select($select)
- ->where($where)
- ->asArray()
- ->one();
- if (empty($info['travel_id'])) {
- return [];
- }
- return $info;
- }
-
- /**
- * Des:获取用户的行程列表
- * Name: getUserTravelList
- * @param $param
- * @return array
- * @author 倪宗锋
- */
- public function getUserTravelList($param)
- {
- $siteConfig = Util::getSiteConfig();
- $codeUrl = $siteConfig['fx_host'] . "/fx/?r=weChat/we-chat/q-code&qCode=";
- $select = [
- 'a.travel_id',//ID
- 'start_date' => new Expression('DATE(a.start_time)'),//出发日期
- 'if_today' => new Expression('if(date(a.start_time)=DATE(NOW()),1,0)'),//是否今天
- 'start_time' => new Expression("DATE_FORMAT(a.start_time,'%H:%i')"),//出发时间
- 'status_des' => new Expression("case 1
- WHEN NOW() <= a.start_time THEN '待出行'
- WHEN NOW() > a.start_time and NOW()< a.end_time THEN '进行中'
- ELSE '已完成'
- END"
- ),
- 'status_id' => new Expression("case 1
- WHEN NOW() <= a.start_time THEN 1
- WHEN NOW() > a.start_time and NOW()< a.end_time THEN 2
- ELSE 3
- END"
- ),
- 'a.cs_order_id',
- 'code_url' => new Expression("concat('{$codeUrl}','',a.cs_order_id)"),
- 'if_comment' => new Expression("if(b.travel_id is NULL, 0, 1)"),
- 'a.start_area_name',
- 'a.end_area_name',
- 'a.end_res',
- 'a.start_res',
- 'a.prod_id',
- 'start_time_all' => 'start_time'
- ];
- $where = ['and'];
- $where[] = ['=', 'a.u_id', $param['u_id']];
- if ($param['status_id'] == 3) {
- $where[] = ['>=', 'now()', new Expression('a.end_time')];
- $order = 'a.start_time desc,a.travel_id';
- } else {
- $where[] = ['<', 'now()', new Expression('a.end_time')];
- $order = 'a.start_time,a.travel_id';
- }
- $offset = ($param['current_page'] - 1) * $param['page_size'];
- $list = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->leftJoin(ProdComment::tableName() . ' b', 'a.travel_id =b.travel_id')
- ->where($where)
- ->limit($param['page_size'])
- ->offset($offset)
- ->orderBy($order)
- ->asArray()
- ->all();
- if (empty($list['0'])) {
- return [];
- }
- return $list;
-
- }
-
- /**
- * Des:获取用户行程ID
- * Name: getUserAllTravel
- * @param $u_id
- * @return array|ActiveRecord[]
- * @author 倪宗锋
- */
- public function getUserAllTravelId($u_id)
- {
- $select = [
- 'travel_id',
- 'cs_order_id'
- ];
- $where = ['=', 'u_id', $u_id];
- $list = self::find()->select($select)
- ->where($where)
- ->indexBy('cs_order_id')
- ->orderBy('start_time desc')
- ->asArray()
- ->all();
- if (empty($list)) {
- return [];
- }
- return $list;
- }
-
- /**
- * Des:删除旧数据
- * Name: delByIds
- * @param $del
- * @param $u_id
- * @return array
- * @author 倪宗锋
- */
- public function delByIds($del, $u_id)
- {
- if (empty($del)) {
- return Util::returnArrSu();
- }
- $where = [
- 'and',
- ['in', 'cs_order_id', $del],
- ['=', 'u_id', $u_id]
- ];
- $tab = clone $this;
- $int = $tab::deleteAll($where);
- if (empty($int)) {
- return Util::returnArrEr('删除旧数据失败!');
- }
- return Util::returnArrSu();
- }
-
- /**
- * Des:添加记录
- * Name: addNews
- * @param $new
- * @param $u_id
- * @return array
- * @author 倪宗锋
- */
- public function addNews($new, $u_id)
- {
- $orderMain = new OrderMain();
- $flag = true;
- foreach ($new as $val) {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $getProdId = $orderMain->getProdIdByCsOrderId($val['cs_order_id']);
- /**插入行程表*/
- $data = [
- 'start_time' => date('Y-m-d H:i:s', strtotime($val['start_time'])),
- 'end_time' => date('Y-m-d H:i:s', strtotime($val['end_time'])),
- 'u_id' => $u_id,
- 'cs_order_id' => $val['cs_order_id'],
- 'prod_id' => $getProdId,
- 'start_res_id' => $val['start_res_id'],
- 'start_res' => $val['start_res'],
- 'end_res_id' => $val['end_res_id'],
- 'end_res' => trim($val['end_res']),
- 'start_area_name' => trim($val['start_area_name']),
- 'end_area_name' => trim($val['end_area_name']),
- 'start_longitude' => trim($val['start_longitude']),
- 'start_latitude' => trim($val['start_latitude']),
- 'contacts_name' => trim($val['customer_name']),
- 'contacts_phone' => trim($val['customer_mobile']),
- 'contacts_ID' => trim($val['customer_id_no']),
- ];
- $clone=clone $this;
- $clone->isNewRecord = true;
- $clone->setAttributes($data);
- $res = $clone->save(false);
- if ($res === false) {
- $flag = false;
- $transaction->rollBack();
- continue;
- }
- $transaction->commit();
- } catch (Exception $e) {
- $flag = false;
- $transaction->rollBack();
- continue;
- }
- }
- if ($flag == false) {
- return Util::returnArrEr('新增异常!');
- }
- return Util::returnArrSu();
- }
-
-
- /**
- * Des:添加虚拟记录
- * Name: addNews
- * @param $new
- * @param $u_id
- * @return array
- * @author
- */
- public function getInfoByTravelOne($param)
- {
- $select = [
- 'start_date' => new Expression('DATE(start_time)'),//出发日期
- 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
- 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间
- 'travel_id',
- 'end_time',
- 'u_id',
- 'prod_id',
- 'cs_order_id',
- 'start_res_id',
- 'end_res_id',
- 'end_res',
- 'start_res',
- 'start_area_name',
- 'end_area_name',
- 'start_longitude',
- 'start_latitude',
- 'contacts_name',
- 'contacts_phone',
- 'contacts_ID',
- ];
- }
-
-
- public function getInfoByTravel($param)
- {
- $select = [
- 'start_date' => new Expression('DATE(start_time)'),//出发日期
- 'if_today' => new Expression('if(date(start_time)=DATE(NOW()),1,0)'),//是否今天
- 'start_time' => new Expression("DATE_FORMAT(start_time,'%H:%i')"),//出发时间
- 'travel_id',
- 'end_time',
- 'u_id',
- 'prod_id',
- 'cs_order_id',
- 'start_res_id',
- 'end_res_id',
- 'end_res',
- 'start_res',
- 'start_area_name',
- 'end_area_name',
- 'start_longitude',
- 'start_latitude',
- 'contacts_name',
- 'contacts_phone',
- 'contacts_ID',
- ];
- }
- }
|