adamyxt / helper
Various custom plug-ins used by the project
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Type:yii2-extension
Requires
- php: >=7.1.19
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2025-07-26 16:34:39 UTC
README
Various custom plug-ins used by the project
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist adamyxt/helper "*"
or add
"adamyxt/helper": "*"
to the require section of your composer.json
file.
Usage
根据传输数据生成签名方式传递数据帮助类使用方法(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()); }