adamyxt / helper
项目使用的各种自定义插件
dev-master
2019-05-07 08:54 UTC
Requires
- php: >=7.1.19
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-21 12:38:40 UTC
README
项目使用的各种自定义插件
安装
安装此扩展的首选方法是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist adamyxt/helper "*"
或者
"adamyxt/helper": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
使用方法
根据传输数据生成签名方式传递数据帮助类使用方法(API传输数据加密方式)
1配置组件 'components' => [ 'encrypt' => [ 'class' => 'common\components\crypt\Encrypt', 'key' => '123', ], ], key设置自己生成的 2使用 $encrypt = Yii::$app->get('encrypt'); 数据格式 $data = [ 'sn' => 'sn123456789, 'timestamp' => time(), 'user_id' => 45, 'type' => 2, 'num' => 455, ]; $sign = $encrypt->encrypt($data); $data['sign'] = $sign; 将计算出的签名sign加入data并传输data ``` ----- 数据库批量修改封装帮助类使用方法(配合事物使用,此方法适用于批量修改数字型字段的加减) : ```php $data = [ 1 => [ 'num' => [ 'value' => 45, 'type' => MysqlHelper::UPDATE_PLUS ], 'create_at' => time(), 'ice_num' => 6 ], 2 => [ 'num' => [ 'value' => 45, 'type' => MysqlHelper::UPDATE_MINUS ], 'create_at' => time(), 'ice_num' => 3 ], 3 => [ 'num' => 456, 'ice_num' => 9, 'create_at' => time() ], 5 => [ 'num' => 12783, 'ice_num' => 7, 'create_at' => time() ], ]; //二维数组键为where条件(比如说上面的意思是修改id为1的num,create_at,ice_num字段),每个修改的字段可以单独设置为替换,加,减,不设置默认为替换 $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { //test为表名,id为where条件字段 if (!MysqlHelper::batchUpdate('test', 'id', $data)) { throw new Exception(123); } $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); var_dump($e->getMessage()); }