|
- <?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;
- }
- }
|