示例#1
0
 public function uninstall($code)
 {
     $row = (new \yii\db\Query())->select(['id', 'shipping_name', 'print_bg'])->from(self::tableName())->where(['shipping_code' => $code])->limit(1)->one();
     if (!$row) {
         return true;
     }
     $shipping_id = $row['id'];
     $shipping_name = $row['shipping_name'];
     //获取配送地区id
     $rows = (new \yii\db\Query())->select(['id'])->from(ShippingArea::tableName())->where(['shipping_id' => $shipping_id])->all();
     $all = UtilD::getCol($rows);
     $in = UtilD::db_create_in(join(',', $all));
     $conn = \Yii::$app->getDb();
     $transaction = $conn->beginTransaction();
     try {
         $sql1 = "DELETE FROM " . AreaRegion::tableName() . " WHERE shipping_area_id " . $in;
         $sql2 = "DELETE FROM " . ShippingArea::tableName() . " WHERE id=" . $shipping_id;
         $sql3 = "DELETE FROM " . Shipping::tableName() . " WHERE id=" . $shipping_id;
         $conn->createCommand($sql1)->execute();
         $conn->createCommand($sql2)->execute();
         $conn->createCommand($sql3)->execute();
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
     //删除上传的非默认快递单
     if ($row['print_bg'] != '' && !UtilD::is_print_bg_default($row['print_bg'])) {
         @unlink(\Yii::getAlias('@web') . DIRECTORY_SEPARATOR . $row['print_bg']);
     }
     AdminLog::admin_log(addslashes($shipping_name), 'uninstall', 'shipping');
     return true;
 }
示例#2
0
 public function getShipingAreaList($shipping_id, $page = 1, $pageSize = 10)
 {
     $q = (new yii\db\Query())->select('*')->from(self::tableName());
     if ($shipping_id) {
         $q->where(['id' => $shipping_id]);
     }
     $pages = new Pagination(['totalCount' => $q->count(), 'defaultPageSize' => $pageSize]);
     $result = $q->offset($pages->offset)->limit($pages->limit)->all();
     $list = [];
     foreach ($result as $key => $row) {
         $sql = "SELECT r.area_name FROM " . AreaRegion::tableName() . " AS a, " . Area::tableName() . " AS r " . " WHERE a.region_area = r.area_code " . " AND a.shipping_area_id = {$shipping_id}";
         $regions = UtilD::getCol(\Yii::$app->getDb()->createCommand($sql)->queryAll());
         $row['shipping_area_regions'] = empty($regions) ? '<a href="' . Url::toRoute(['/shipping-area/region', 'id' => $row['shipping_area_id']]) . '" style="color:red">' . \Yii::t('shipping', 'empty_regions') . '</a>' : $regions;
         $list[] = $row;
     }
     return $list;
 }