255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'order_id' => 'Order ID', 'prod_id' => 'Prod ID', 'count' => 'Count', 'unit_price' => 'Unit Price', 'total_price' => 'Total Price', 'delete_flag' => 'Delete Flag', 'commission' => 'Commission', 'prod_name' => 'Prod Name', ]; } /** * Des:获取订单佣金 * Name: getOrderCommission * @param $orderId * @return int * @author 倪宗锋 */ public function getOrderCommission($orderId) { $select = [ new Expression("IFNULL(SUM(b.commission*a.count),0) 'commission'"), 'order_id' ]; try { $result = self::find()->select($select) ->from(self::tableName() . ' as a') ->innerJoin(ProdMain::tableName() . ' as b', 'a.prod_id = b.prod_id') ->where(['=', 'a.order_id', $orderId]) ->asArray() ->one(); } catch (Exception $e) { $result['commission'] = 0; } return $result['commission']; } /** * Function Description:插入子订单 * Function Name: insertInfo * @param $prod_arr array * @param $oderId * @param $category_id * * @return bool * * @author 娄梦宁 */ public function insertInfo($prod_arr, $oderId, $category) { if ($category['category_id'] == 2 && $category['sign'] || $category['category_id'] == 4) { $sql = "INSERT into order_info(order_id,prod_name, total_price, count, unit_price, prod_id,commission) SELECT {$oderId},prod_name, {$prod_arr['prod_price']}*{$prod_arr['prod_count']} price, {$prod_arr['prod_count']},{$prod_arr['prod_price']},prod_id,commission from prod_main where prod_id ={$prod_arr['prod_id']}"; } else { $sql = "INSERT into order_info(order_id,prod_name, total_price, count, unit_price, prod_id,commission) SELECT {$oderId},prod_name, prod_price*{$prod_arr['prod_count']} price, {$prod_arr['prod_count']},prod_price,prod_id,commission from prod_main where prod_id ={$prod_arr['prod_id']}"; } $res = $this->getDb()->createCommand($sql)->execute(); if (!$res) { return false; } return true; } /** * Des:获取订单子产品数组 * Name: getProdArrayByOrderId * @param $orderId * @return array * @author 倪宗锋 */ public function getProdArrayByOrderId($orderId) { $where = [ 'and', ['=', 'order_id', $orderId], ['=', 'delete_flag', 0] ]; $select = [ 'order_id', 'prod_id', 'count', 'unit_price', 'total_price', 'commission', 'prod_name', ]; $getProd = self::find()->select($select) ->where($where) ->asArray() ->all(); if (empty($getProd[0])) { return []; } return $getProd; } /** * Des:获取订单子产品数组 * Name: getProdArrayByOrderId * @param $orderIds * @return array * @author 倪宗锋 */ public function getProdArrForPay($orderIds) { $where = [ 'and', ['in', 'order_id', $orderIds], ['=', 'delete_flag', 0] ]; $select = [ 'cnt' => new Expression("SUM(count)"), 'unit_price' => new Expression("ROUND(SUM(total_price)/SUM(count),2)"), 'prod_name', ]; $getProd = self::find()->select($select) ->where($where) ->asArray() ->groupBy('prod_name') ->all(); if (empty($getProd[0])) { return []; } return $getProd; } /** * 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; } /** * Function Description:获取订单车票信息 * Function Name: getOrderPriceDetail * @param $order_id * * @return array|ActiveRecord[] * * @author LUOCJ */ public function getOrderPriceDetail($order_id) { //查询订单乘车人数 $where = ['and']; $where[] = ['=', 'order_id', $order_id]; $where[] = ['=', 'delete_flag', 0]; $info = self::find()->select('count,unit_price')->from(self::tableName())->where($where)->groupBy('prod_id')->asArray()->all(); if (count($info) > 0) { foreach ($info as &$v) { $v['unit_price'] = $this->dealFloat($v['unit_price']); } } return $info; } /** * Des:获取产品数组 * Name: getFreeWalkProdArr * @param $order_id * @return array * @author 倪宗锋 */ public function geProdArr($order_id) { $select = [ 'prod_id' => 'b.bus_id', 'prod_name' => 'b.prod_name', 'prod_num' => 'a.count' ]; $where = ['=', 'a.order_id', $order_id]; $getProdArr = self::find()->select($select) ->from(self::tableName() . ' a') ->innerJoin(ProdMain::tableName() . ' b', 'a.prod_id = b.prod_id') ->where($where) ->asArray(true) ->all(); return $getProdArr; } }