|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802 |
- <?php
-
- namespace common\models;
-
- use common\util\Util;
- use Yii;
- use yii\base\Exception;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "prod_category".
- *
- * @property integer $pro_cate_id
- * @property string $pro_cate_name
- * @property integer $category_id
- * @property string $show_price
- * @property string $show_img
- * @property integer $sales_count
- * @property string $memo
- * @property string $commission
- * @property integer $create_user_id
- * @property integer $is_recom
- * @property string $create_time
- * @property string $update_time
- * @property integer $delete_flag
- * @property string $update_user
- * @property string $address
- * @property integer $bus_ticket_id
- * @property integer $bus_line_type
- */
- class ProdCategory extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'prod_category';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['pro_cate_name', 'category_id'], 'required'],
- [['category_id', 'sales_count', 'create_user_id', 'is_recom', 'delete_flag', 'bus_ticket_id', 'bus_line_type'], 'integer'],
- [['show_price', 'commission', 'original_price'], 'number'],
- [['create_time', 'update_time', 'sign'], 'safe'],
- [['pro_cate_name', 'address'], 'string', 'max' => 100],
- [['show_img', 'sign', 'prod_des'], 'string', 'max' => 255],
- [['memo',], 'string', 'max' => 65536],
- [['update_user', 'close_sale_time'], 'string', 'max' => 50],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'pro_cate_id' => 'Pro Cate ID',
- 'pro_cate_name' => 'Pro Cate Name',
- 'category_id' => 'Category ID',
- 'show_price' => 'Show Price',
- 'show_img' => 'Show Img',
- 'sign' => 'sign',
- 'prod_des' => 'prod_des',
- 'sales_count' => 'Sales Count',
- 'memo' => 'Memo',
- 'commission' => 'Commission',
- 'create_user_id' => 'Create User ID',
- 'is_recom' => 'Is Recom',
- 'create_time' => 'Create Time',
- 'update_time' => 'Update Time',
- 'delete_flag' => 'Delete Flag',
- 'update_user' => 'Update User',
- 'address' => 'Address',
- 'bus_ticket_id' => 'Bus Ticket ID',
- 'bus_line_type' => 'Bus Line Type',
- ];
- }
-
- /**
- * Function Description:热销商品推荐10个
- * Function Name: GetHotProd
- * @param string $searchStr
- *
- * @return array|\yii\db\ActiveRecord[]
- *
- * @author 娄梦宁
- */
- public function GetHotProd($searchStr = '')
- {
- $where = [
- 'and',
- ['<>', 'show_img', ''],
- ['=', 'a.delete_flag', 0],
- ['=', 'b.delete_flag', 0],
- ['=', 'b.system', 1]
- ];
- if ($searchStr != '') {
- $where[] = ['like', 'pro_cate_name', $searchStr];
- }
- $result = self::find()->select(['pro_cate_id', 'sales_count', "IFNULL(prod_des, '') prod_des", 'pro_cate_name', 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
- ->from(self::tableName() . ' a')
- ->innerJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id')
- ->where($where)
- ->orderBy(['sales_count' => SORT_DESC, 'pro_cate_id' => SORT_DESC])
- ->limit(10)
- ->asArray()
- ->all();
- foreach($result as &$v){
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
- /**
- * Function Description:推荐产品列表
- * Function Name: GetRecommendProd
- * @param string $where
- *
- * @return array|\yii\db\ActiveRecord[]
- *
- * @author 娄梦宁
- */
- public function GetRecommendProd($where = '')
- {
- if ($where == '') {
- $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
- ->where(['and', ['=', 'is_recom', 1], ['!=', 'show_img', ''], ['=', 'a.delete_flag', 0], ['=', 'b.system', 1]])
- ->orderBy(['pro_cate_id' => SORT_DESC])
- ->asArray()
- ->all();
- } else {
- $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
- ->where(['and', ['=', 'is_recom', 1], ['!=', 'show_img', ''], ['=', 'a.delete_flag', 0], ['=', 'b.system', 1]])
- ->andWhere(['like', 'pro_cate_name', $where])
- ->orderBy(['pro_cate_id' => SORT_DESC])
- ->asArray()
- ->all();
- }
- foreach($result as &$v){
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
- /**
- * Function Description:首页列表查询产品
- * Function Name: GetListProd
- * @param $prod_id
- * @param string $where
- *
- * @return array|\yii\db\ActiveRecord[]
- *
- * @author 娄梦宁
- */
- public function GetListProd($prod_id, $where = '')
- {
- if ($where == '') {
- $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
- ->where(['and', ['=', 'b.cms_cate_id', $prod_id], ['<>', 'a.show_img', ''], ['=', 'a.delete_flag', 0]])
- ->orderBy(['show_sort' => SORT_ASC, 'a.pro_cate_id' => SORT_DESC])
- ->asArray()
- ->all();
- } else {
- $result = self::find()->select(['pro_cate_id', 'sales_count', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id', 'show_price', "concat(show_img,'.','min.jpg') as show_img"])
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod b', 'a.pro_cate_id=b.prod_cate_id and b.delete_flag=0')
- ->where(['and', ['=', 'b.cms_cate_id', $prod_id], ['<>', 'a.show_img', ''], ['=', 'a.delete_flag', 0]])
- ->andWhere(['like', 'pro_cate_name', $where])
- ->orderBy(['show_sort' => SORT_ASC, 'a.pro_cate_id' => SORT_DESC])
- ->asArray()
- ->all();
- }
- foreach($result as &$v){
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
- /**
- * Function Description:非巴士产品获取详情
- * Function Name: getProdDetail
- * @param $pro_cate_id
- *
- * @return array|null|\yii\db\ActiveRecord
- *
- * @author 娄梦宁
- */
- public function getProdDetail($pro_cate_id)
- {
- $result = self::find()->select(['pro_cate_id', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'category_id', 'show_img', 'memo booking_notice', 'sign', 'show_price', 'close_sale_time',
- "(select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=$pro_cate_id limit 1)) as category_name"])
- ->from(self::tableName())
- ->where(['and', ['=', 'pro_cate_id', $pro_cate_id], ['=', 'delete_flag', 0]])
- ->asArray()
- ->one();
- $result['show_price'] = $this->dealFloat($result['show_price']);
- return $result;
- }
-
- /**
- * Des:获取产品详细信息
- * Name: getProdInfo
- * @param $pro_cate_id
- * @return array|null|\yii\db\ActiveRecord
- * @author 倪宗锋
- */
- public function getProdCateInfo($pro_cate_id)
- {
- $result = self::find()
- ->from(self::tableName())
- ->where(['=', 'pro_cate_id', $pro_cate_id])
- ->asArray()
- ->one();
- return $result;
- }
-
- /**
- * Function Description:巴士产品获取详情
- * Function Name: getBusProdDetail
- * @param $pro_cate_id
- *
- * @return array|null|\yii\db\ActiveRecord
- *
- * @author 娄梦宁
- */
- public function getBusProdDetail($pro_cate_id)
- {
- $result = self::find()->select(['pro_cate_id', 'pro_cate_name', "IFNULL(prod_des, '') prod_des", 'category_id', 'sign', 'show_img', 'IFNULL(close_sale_time,24) as close_sale_time', "(select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=$pro_cate_id limit 1)) as category_name"
- , 'b.start_area_name', 'b.start_area_id', 'b.start_res_name', 'b.end_res_name', 'b.end_area_name', 'b.end_area_id', 'memo booking_notice'])
- ->from(self::tableName() . ' as a')
- ->leftJoin('bus_ticket b', 'a.bus_ticket_id=b.ticket_id')
- ->where(['and', ['=', 'pro_cate_id', $pro_cate_id]])
- ->asArray()
- ->one();
- return $result;
- }
-
- /*
- * 后台产品列表
- */
- public function AdminGetList($param)
- {
- $where = ['and', ['=', 'a.delete_flag', 0]];
- if ($param['category_id'] != '') {
- $where[] = ['=', 'b.cms_cate_id', $param['category_id']];
- }
- if ($param['pro_cate_name'] != '') {
- $where[] = ['like', 'pro_cate_name', $param['pro_cate_name']];
- }
- if ($param['is_recom'] != '') {
- $where[] = ['=', 'is_recom', $param['is_recom']];
- }
- $offset = ($param['current_page'] - 1) * $param['page_size'];
- $select = [
- 'pro_cate_id',
- 'a.category_id',
- "if(a.category_id=1,if(a.sign is not null,concat(c.category_name,'(主线路)'),concat(c.category_name,'(子线路)')),c.category_name) as base_category",
- 'pro_cate_name', 'close_sale_time',
- 'memo', "IFNULL(prod_des, '') prod_des",
- 'commission', 'show_img',
- 'is_recom as is_recom_id',
- 'if(is_recom=1,"已推荐","未推荐") as is_recom'
- , "(select 1) as commission_way_id", "(select '按金额') as commission_way",
- "ifnull((select category_name from cms_category where cms_category_id =(select cms_cate_id from cms_category_prod where prod_cate_id=a.pro_cate_id limit 1)),'') as category_name"
- , "ifnull(b.cms_cate_id,-1) as cms_category_id"
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod as b', 'b.prod_cate_id = a.pro_cate_id')
- ->innerJoin(BaseCategory::tableName() . ' c', 'c.category_id = a.category_id')
- ->where($where)
- ->groupBy('a.pro_cate_id')
- ->orderBy('a.pro_cate_id DESC')
- ->offset($offset)
- ->limit((int)$param['page_size'])
- ->asArray()
- ->all();
-
-
- $result1 = self::find()->select('count(1) as count')
- ->from(self::tableName() . ' a')
- ->leftJoin('cms_category_prod as b', 'b.prod_cate_id=a.pro_cate_id')
- ->asArray()
- ->where($where)
- ->one();
- $result1 = $result1['count'];
- return ['list' => $result, 'count' => $result1];
- }
-
- /*
- * 产品推荐
- */
- public function Recommend($pro_cate_id)
- {
- $is_recom = self::find()->select(["is_recom"])->from(self::tableName())->where(['=', 'pro_cate_id', $pro_cate_id])->asArray()->one();
- if ($is_recom['is_recom'] == 1) {
- $count = self::updateAll(['is_recom' => 0], ['=', 'pro_cate_id', $pro_cate_id]);
- } else {
- $count = self::updateAll(['is_recom' => 1], ['=', 'pro_cate_id', $pro_cate_id]);
- }
- return $count;
- }
-
- /*
- * 添加产品
- */
- public function addProd($param)
- {
- $values = [
- 'category_id' => $param['category_id'],
- 'pro_cate_name' => $param['pro_cate_name'],
- 'memo' => $param['memo'],
- 'sales_count' => rand(1, 10),
- 'show_img' => $param['show_img'],
- 'create_time' => date('Y-m-d H:i:s'),
- 'prod_des' => $param['prod_des'],
- 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc
- ];
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $this->attributes = $values;
- $res = $this->insert();
- if (!$res) {
- throw new Exception('添加出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /*
- * 修改show price
- */
- public function changeShowPrice($pro_cate_id)
- {
- //查当前产品的子产品最低价
- $show_price = ProdMain::find()->select(['min(prod_price) as price'])->from('prod_main')->where(['and', ['=', 'delete_flag', '0'], ['=', 'prod_cate_id', $pro_cate_id]])->asArray()->one();
- $show_price = $show_price['price'];
- $count = self::updateAll(['show_price' => $show_price], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
- return $count;
- }
-
- /*
- * 自定义佣金
- */
- public function DefineCommission($pro_cate_id, $commission)
- {
- $count = self::updateAll(['commission' => $commission], ['and', ['=', 'pro_cate_id', $pro_cate_id]]);
- return $count;
- }
-
- /*
- * 后台修改产品信息
- */
- public function uptAdminProd($param)
- {
- $values = [
- 'category_id' => $param['category_id'],
- 'pro_cate_name' => $param['pro_cate_name'],
- 'memo' => $param['memo'],
- 'show_img' => $param['show_img'],
- 'prod_des' => $param['prod_des'],
- 'update_time' => date('Y-m-d H:i:s'),
- 'close_sale_time' => $param['close_sale_time'] //截止售卖时间 2017-05-18 fuhc
- ];
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $uptOne = self::findOne(['pro_cate_id' => $param['pro_cate_id']]);
- $uptOne->attributes = $values;
- $res = $uptOne->update();
- if ($res === false) {
- throw new Exception('添加出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /*
- * 产品增量
- */
- public function addCount($pro_cate_id, $cnt)
- {
- $sql = '' . "UPDATE prod_category
- set sales_count=sales_count+$cnt
- where pro_cate_id = $pro_cate_id
- ";
- $res = $this->getDb()->createCommand($sql)->execute();
- if (!$res) {
- return false;
- }
- return true;
- }
-
- /**
- * Des:
- * Name: getEntranceTicket
- * @return array
- * @author 倪宗锋
- */
- public function getEntranceTicket()
- {
- $result = self::find()
- ->from(self::tableName())
- ->where(['and', ['<>', 'sign', ''], ['=', 'category_id', 2], ['=', 'delete_flag', 0]])
- ->indexBy('sign')
- ->asArray()
- ->all();
- return $result;
- }
-
- /**
- * Des:同步门票数据
- * Name: addEntranceTicketFormCs
- * @param $prodArr
- * @return int
- * @throws \yii\db\Exception
- * @author 倪宗锋
- */
- public function addEntranceTicketFormCs($prodArr)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- /**添加产品主表数据***************/
- $prodValues = [];
- $prodKeys = [
- 'pro_cate_name',
- 'category_id',
- 'create_time',
- 'sign',
- ];
- foreach ($prodArr as $key => $val) {
- $prodVal = [];
- $prodVal[] = $val['name'];
- $prodVal[] = 2;
- $prodVal[] = date('Y-m-d H:i:s');
- $prodVal[] = $key;
- $prodValues[] = $prodVal;
- }
- $count = Yii::$app->db->createCommand()->batchInsert('prod_category', $prodKeys, $prodValues)->execute();
- if ($count == 0) {
- $transaction->rollBack();
- return false;
- }
- /**获取新添加的产品主表数据及其ID**/
- $signArr = array_keys($prodArr);
- $result = self::find()
- ->from(self::tableName())
- ->where(['and', ['in', 'sign', $signArr], ['=', 'category_id', 2]])
- ->indexBy('sign')
- ->asArray()
- ->all();
- /**将数据产褥prod_main表中*/
- $prodMainValues = [];
- $prodMainKeys = ['prod_cate_id', 'prod_name', 'create_time', 'bus_id'];
- foreach ($result as $key => $val) {
- if (!empty($prodArr[$val['sign']]['sub_ticket']) && count($prodArr[$val['sign']]['sub_ticket']) > 0) {
- $subTicket = $prodArr[$val['sign']]['sub_ticket'];
- foreach ($subTicket as $subVal) {
- $prodMainVal = [];
- $prodMainVal[] = $val['pro_cate_id'];
- $prodMainVal[] = $subVal['prod_name'];
- $prodMainVal[] = date('Y-m-d H:i:s');
- $prodMainVal[] = $subVal['prod_id'];
- $prodMainValues[] = $prodMainVal;
- }
-
- }
- }
- $count = Yii::$app->db->createCommand()->batchInsert('prod_main', $prodMainKeys, $prodMainValues)->execute();
-
- if ($count == 0) {
- $transaction->rollBack();
- return false;
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /**
- * Des: 删除门票数据
- * Name: delEntranceTicketFormCs
- * @author 倪宗锋
- */
- public function delEntranceTicketFormCs($prodArr)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $values = [
- 'delete_flag' => 1
- ];
- $signArr = array_keys($prodArr);
- $res = self::updateAll($values, ['in', 'sign', $signArr]);
- if ($res === false) {
- throw new Exception('添加出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /**
- * Des:修改订单状态为激活
- * Name: interEntranceTicketFormCs
- * @param $new_bus_arr_inter
- * @return bool
- * @throws \yii\db\Exception
- * @author 倪宗锋
- */
- public function interEntranceTicketFormCs($new_bus_arr_inter)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $values = [
- 'delete_flag' => 0
- ];
- $signArr = array_keys($new_bus_arr_inter);
- $res = self::updateAll($values, ['in', 'sign', $signArr]);
- if ($res === false) {
- throw new Exception('编辑出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /**
- * Des:每日增加产品的销售量 每月1号重置产品的销售量
- * Name: setSaleCnt
- * @param $day
- * @return bool
- * @throws \yii\db\Exception
- * @author 倪宗锋
- */
- public function setSaleCnt($day)
- {
- if ($day == 1) {
- $values = [
- 'sales_count' => new Expression("1+ROUND(RAND()*10,0)")
- ];
- } else {
- $values = [
- 'sales_count' => new Expression("sales_count+sales_count*0.05+1+ROUND(RAND()*5,0)")
- ];
- }
- $transaction = Yii::$app->db->beginTransaction();
- try {
-
- $res = self::updateAll($values);
- if ($res === false) {
- throw new Exception('添加出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /**
- * Des:LBS获取产品列表
- * Name: getLBSListByCmsCate
- * @param $point
- * @param $cms_cate_id
- * @return array
- * @author 倪宗锋
- */
- public function getLBSListByCmsCate($point, $cms_cate_id)
- {
- $pointArr = explode(',', $point);//经纬度坐标
- if (empty($pointArr['0']) || empty($pointArr['1'])) {
- return [];
- }
- $longitude = $pointArr['0'];
- $latitude = $pointArr['1'];
- $sql = '' . "SELECT round(if(a.start_lbs>a.end_lbs,a.end_lbs,a.start_lbs),3) 'lbs', b.pro_cate_id,b.sales_count,
- b.pro_cate_name,IFNULL(prod_des, '') prod_des,if(category_id=1,(if(sign is null,category_id,1000)),category_id) as category_id
- ,show_price,concat(show_img,'.','min.jpg') as show_img
- from (
- select ticket_id,line_type,sqrt(
- ((({$longitude}-start_res_longitude)*PI()*12656*cos((($latitude+start_res_latitude)/2)*PI()/180)/180)
- * (({$longitude}-start_res_longitude)*PI()*12656*cos ((($latitude+start_res_latitude)/2)*PI()/180)/180))
- + ((($latitude-start_res_latitude)*PI()*12656/180)
- * (($latitude-start_res_latitude)*PI()*12656/180))
- )/2 as start_lbs,
- sqrt(
- ((({$longitude}-end_res_longitude)*PI()*12656*cos((($latitude+end_res_latitude)/2)*PI()/180)/180)
- *(({$longitude}-end_res_longitude)*PI()*12656*cos ((($latitude+end_res_latitude)/2)*PI()/180)/180)
- )+((($latitude-end_res_latitude)*PI()*12656/180)
- *(($latitude-end_res_latitude)*PI()*12656/180))
- )/2 as end_lbs,
- start_res_longitude, start_res_latitude,end_res_longitude,end_res_latitude
- from bus_ticket where
- start_res_longitude is not null and end_res_longitude is not NULL
- and start_res_latitude is not null and end_res_latitude is not NULL
- ) a
- JOIN prod_category b on a.ticket_id=b.bus_ticket_id
- JOIN cms_category_prod c on b.pro_cate_id = c.prod_cate_id
- WHERE b.sign is NULL and c.cms_cate_id={$cms_cate_id} and b.show_img <> '' and b.delete_flag=0
- ORDER BY lbs
- LIMIT 10 ";
- $result = Yii::$app->getDb()->createCommand($sql)->queryAll();
- foreach($result as &$v){
- $v['show_price'] = $this->dealFloat($v['show_price']);
- }
- return $result;
- }
-
-
- /**
- * Des:
- * Name: getEntranceHotel
- * @return array
- * @author 付泓程
- */
- public function getEntranceHotel()
- {
- $result = self::find()
- ->from(self::tableName())
- ->where(['and', ['<>', 'sign', ''], ['=', 'category_id', 3]])
- ->indexBy('sign')
- ->asArray()
- ->all();
- return $result;
- }
-
-
- /**
- * Des:同步酒店数据
- * Name: addEntranceHotelFormCs
- * @param $prodArr
- * @return bool
- * @throws \yii\db\Exception
- * @author 付泓程
- */
- public function addEntranceHotelFormCs($prodArr)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- /**添加产品主表数据***************/
- $prodValues = [];
- $prodKeys = [
- 'pro_cate_name',
- 'category_id',
- 'create_time',
- 'sign',
- ];
- foreach ($prodArr as $key => $val) {
- $prodVal = [];
- $prodVal[] = $val['name'];
- $prodVal[] = 3;
- $prodVal[] = date('Y-m-d H:i:s');
- $prodVal[] = $key;
- $prodValues[] = $prodVal;
- }
- $count = Yii::$app->db->createCommand()->batchInsert('prod_category', $prodKeys, $prodValues)->execute();
- if ($count == 0) {
- $transaction->rollBack();
- return false;
- }
- /**获取新添加的产品主表数据及其ID**/
- $signArr = array_keys($prodArr);
- $result = self::find()
- ->from(self::tableName())
- ->where(['and', ['in', 'sign', $signArr], ['=', 'category_id', 3]])
- ->indexBy('sign')
- ->asArray()
- ->all();
- /**将数据插入prod_main表中*/
- $prodMainValues = [];
- $prodMainKeys = ['prod_cate_id', 'prod_name', 'create_time', 'bus_id'];
- foreach ($result as $key => $val) {
- if (!empty($prodArr[$val['sign']]['sub_ticket']) && count($prodArr[$val['sign']]['sub_ticket']) > 0) {
- $subTicket = $prodArr[$val['sign']]['sub_ticket'];
- foreach ($subTicket as $subVal) {
- $prodMainVal = [];
- $prodMainVal[] = $val['pro_cate_id'];
- $prodMainVal[] = $subVal['prod_name'];
- $prodMainVal[] = date('Y-m-d H:i:s');
- $prodMainVal[] = $subVal['prod_id'];
- $prodMainValues[] = $prodMainVal;
- }
-
- }
- }
- $count = Yii::$app->db->createCommand()->batchInsert('prod_main', $prodMainKeys, $prodMainValues)->execute();
-
- if ($count == 0) {
- $transaction->rollBack();
- return false;
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
-
- /**
- * Des: 删除酒店数据
- * Name: delEntranceTicketFormCs
- * @author 付泓程
- */
- public function delEntranceHotelFormCs($prodArr)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $values = [
- 'delete_flag' => 1
- ];
- $signArr = array_keys($prodArr);
- $res = self::updateAll($values, ['in', 'sign', $signArr]);
- if ($res === false) {
- throw new Exception('删除出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
-
- /**
- * Des:修改订单状态为激活
- * Name: interEntranceHotelFormCs
- * @param $new_bus_arr_inter
- * @return bool
- * @throws \yii\db\Exception
- * @author 付泓程
- */
- public function interEntranceHotelFormCs($new_bus_arr_inter)
- {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $values = [
- 'delete_flag' => 0
- ];
- $signArr = array_keys($new_bus_arr_inter);
- $res = self::updateAll($values, ['in', 'sign', $signArr]);
- if ($res === false) {
- throw new Exception('编辑出错');
- }
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
-
- /**
- * Function Description:处理价格
- * Function Name: dealFloat
- * @param $float
- *
- * @return float
- *
- * @author LUOCJ
- */
- public function dealFloat($float)
- {
- $int = floor($float);
- if ($float - $int == 0) {
- $float = $int;
- }
- return $float;
- }
- }
|