Commit cae4b465 authored by rlgy's avatar rlgy

账单

parent a6595101
......@@ -24,13 +24,40 @@ class BillController extends BaseController
$model = new Bill();
if ($model->load($post) && $model->validate()) {
$model->status = 0;
if ($model->save(false)) {
//加入队列
Yii::$app->queue->push(new BillJob(['id' => $model->id, 'txid' => $model->txid, 'chain' => $model->chain, 'from' => $model->from]));
return ['code' => 0, 'message' => 'succeed'];
try {
if ($model->save(false)) {
//加入队列
Yii::$app->queue->push(new BillJob(['id' => $model->id, 'txid' => $model->txid, 'chain' => $model->chain, 'from' => $model->from]));
return ['code' => 0, 'message' => 'succeed'];
}
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => '保存失败'];
}
} else {
return ['code' => -1, 'message' => '数据验证失败'];
}
}
public function actionBillList()
{
$post = Yii::$app->request->post();
$from = $post['from'] ?? '';
$coinname = $post['coinname'] ?? '';
$chain = $post['chain'] ?? '';
$page = $post['$page'] ?? 1;
$limit = $post['limit'] ?? 10;
if (empty($from)) {
return ['code' => -1, 'message' => '数据不存在'];
}
$condition = [
['from' => $from],
];
if (!empty($coinname)) {
$condition[] = ['coinname' => $coinname];
}
if (!empty($chain)) {
$condition[] = ['chain' => $chain];
}
return Bill::getList($page, $limit, $condition);
}
}
\ No newline at end of file
......@@ -8,6 +8,9 @@
namespace api\job;
use common\business\BrowerBusiness;
use common\models\pwallet\Bill;
use common\service\brower\Brower;
use yii\base\BaseObject;
use yii\queue\JobInterface;
use yii\queue\Queue;
......@@ -31,8 +34,31 @@ class BillJob extends BaseObject implements JobInterface
*/
public function execute($queue)
{
//todo 查询交易状态, 更改状态
$result = BrowerBusiness::getTransStatus($this->chain, $this->txid);
$f = false;
if ($result['code'] == Brower::TRANS_OK) {
$model = Bill::findOne($this->id);
$model->status = 1;
$data = $result['data'] ?? null;
if ($data) {
$model->height = $data['height'] ?? 0;
if (isset($data['blocktime']) && !empty($data['blocktime'])) {
$model->blocktime = date('Y-m-d H:i:s', $data['blocktime']);
}
}
if ($model->save()) {
$f = true;
}
} elseif ($result['code'] == Brower::TRANS_FAIL) {
$model = Bill::findOne($this->id);
$model->status = -1;
if ($model->save()) {
$f = true;
}
}
if (!$f) {
\Yii::$app->queue->delay(3 * 60)->push(new BillJob(['id' => $this->id, 'txid' => $this->txid, 'chain' => $this->chain, 'from' => $this->from]));
}
return 0;
}
......
2018-07-31 01:24:11 [pid: 2434] - Worker is started
2018-07-31 01:24:11 [pid: 2434] - Worker is stopped (0:00:00)
2018-07-31 01:24:12 [pid: 2637] - Worker is started
2018-07-31 01:24:12 [pid: 2637] - Worker is stopped (0:00:00)
2018-07-31 01:24:13 [pid: 3244] - Worker is started
2018-07-31 01:24:13 [pid: 3244] - Worker is stopped (0:00:00)
2018-07-31 01:24:15 [pid: 3663] - Worker is started
2018-07-31 01:24:15 [pid: 3663] - Worker is stopped (0:00:00)
2018-07-31 01:24:18 [pid: 3711] - Worker is started
2018-07-31 01:24:18 [pid: 3711] - Worker is stopped (0:00:00)
2018-07-31 10:05:01 [pid: 2123] - Worker is started
2018-07-31 10:05:01 [pid: 2123] - Worker is stopped (0:00:00)
2018-07-31 10:05:02 [pid: 2219] - Worker is started
2018-07-31 10:05:02 [pid: 2219] - Worker is stopped (0:00:00)
2018-07-31 10:05:03 [pid: 2277] - Worker is started
2018-07-31 10:05:03 [pid: 2277] - Worker is stopped (0:00:00)
2018-07-31 10:05:05 [pid: 2691] - Worker is started
2018-07-31 10:05:05 [pid: 2691] - Worker is stopped (0:00:00)
2018-07-31 10:05:08 [pid: 2721] - Worker is started
2018-07-31 10:05:08 [pid: 2721] - Worker is stopped (0:00:00)
2018-08-01 01:05:20 [pid: 2388] - Worker is started
2018-08-01 01:05:20 [pid: 2388] - Worker is stopped (0:00:00)
2018-08-01 01:05:21 [pid: 3089] - Worker is started
2018-08-01 01:05:21 [pid: 3089] - Worker is stopped (0:00:00)
2018-08-01 01:05:22 [pid: 3230] - Worker is started
2018-08-01 01:05:22 [pid: 3230] - Worker is stopped (0:00:00)
2018-08-01 01:05:24 [pid: 3591] - Worker is started
2018-08-01 01:05:24 [pid: 3591] - Worker is stopped (0:00:00)
2018-08-01 01:05:27 [pid: 3684] - Worker is started
2018-08-01 01:05:27 [pid: 3684] - Worker is stopped (0:00:00)
2018-08-01 02:05:09 [pid: 2081] - Worker is started
2018-08-01 02:05:09 [pid: 2081] - Worker is stopped (0:00:00)
2018-08-01 02:05:11 [pid: 2182] - Worker is started
2018-08-01 02:05:11 [pid: 2182] - Worker is stopped (0:00:00)
2018-08-01 02:05:12 [pid: 2242] - Worker is started
2018-08-01 02:05:12 [pid: 2242] - Worker is stopped (0:00:00)
2018-08-01 02:05:14 [pid: 2488] - Worker is started
2018-08-01 02:05:14 [pid: 2488] - Worker is stopped (0:00:00)
2018-08-01 02:05:17 [pid: 2514] - Worker is started
2018-08-01 02:05:17 [pid: 2514] - Worker is stopped (0:00:00)
2018-08-02 01:24:36 [pid: 2099] - Worker is started
2018-08-02 01:24:36 [2] api\job\BillJob (attempt: 1, pid: 2099) - Started
2018-08-02 01:24:36 [2] api\job\BillJob (attempt: 1, pid: 2099) - Done (0.001 s)
2018-08-02 01:24:36 [3] api\job\BillJob (attempt: 1, pid: 2099) - Started
2018-08-02 01:24:36 [3] api\job\BillJob (attempt: 1, pid: 2099) - Done (0.001 s)
2018-08-02 01:24:36 [pid: 2099] - Worker is stopped (0:00:00)
2018-08-02 01:24:37 [pid: 3308] - Worker is started
2018-08-02 01:24:37 [pid: 3308] - Worker is stopped (0:00:00)
2018-08-02 01:24:38 [pid: 3324] - Worker is started
2018-08-02 01:24:38 [pid: 3324] - Worker is stopped (0:00:00)
2018-08-02 01:24:40 [pid: 3372] - Worker is started
2018-08-02 01:24:40 [pid: 3372] - Worker is stopped (0:00:00)
2018-08-02 01:24:43 [pid: 3445] - Worker is started
2018-08-02 01:24:43 [pid: 3445] - Worker is stopped (0:00:00)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment