Coder1024
老哥,代码不错,感谢分享!不过放到linux系统上报错:Worksheet not found。
看了代码,路径
/vendor/illusion/yii2-excel/src/
下的文件WorkSheet.php
,Sheet首个字符是大写;
Spreadsheet.php的第52行$this->worksheet = new Worksheet($this->_spreadsheet);
的Worksheet
的sheet首个字符是小写。可修改
WorkSheet.php
的文件名为Worksheet.php
;或者修改class名和调用的地方解决。你这个问题 我今天刚刚遇到, where 先把大的条件放前面
其实是跨库的问题,写了篇文章记录了本次的坑:https://www.jianshu.com/p/e1f5364aa9d6
贴上部分代码
$datas = User::find()->where(['type' => $type])->with('user_type')->all(); if ($datas){ ... $transaction = User::getDb()->beginTransaction(); $transaction->setIsolationLevel(\yii\db\Transaction::SERIALIZABLE); try { $transaction2 = Customer::getDb()->beginTransaction(); $transaction2->setIsolationLevel(\yii\db\Transaction::SERIALIZABLE); try { foreach ($datas as $key => $user) { ... $data = $data2 = $user->getAttributes(); ... $model = new UserInfo(); $model2 = new Customer(); $model->load($data, ""); $model2->load($data2, ""); if($model->save() && $model2->save() && $user->delete()){ $transaction2->commit(); $transaction->commit(); } } } catch(\Throwable $e) { $transaction2->rollBack(); throw $e; } } catch(\Throwable $e) { $transaction->rollBack(); throw $e; } }
- Coder1024 2018-10-25 已签到连续签到2天,获得了10个金钱