|
@@ -3,6 +3,7 @@
|
|
namespace app\index\controller;
|
|
namespace app\index\controller;
|
|
use think\Controller;
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\Db;
|
|
|
|
+use app\common\model\Wallet;
|
|
|
|
|
|
class Plantask extends Controller
|
|
class Plantask extends Controller
|
|
{
|
|
{
|
|
@@ -71,4 +72,66 @@ class Plantask extends Controller
|
|
return $rs;
|
|
return $rs;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //订单支付回调之后的任务,每分钟运行
|
|
|
|
+ public function auto_order_paid(){
|
|
|
|
+
|
|
|
|
+ $map = [
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ 'have_paid' => ['gt',0],
|
|
|
|
+ 'paidtasktime' => 0,
|
|
|
|
+ ];
|
|
|
|
+ $order_list = Db::name('unishop_order')->where($map)->limit(10)->select();
|
|
|
|
+ if(empty($order_list)){
|
|
|
|
+ echo '没有数据';
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $walletmodel = new Wallet();
|
|
|
|
+
|
|
|
|
+ foreach($order_list as $key => $order){
|
|
|
|
+
|
|
|
|
+ //直推代理商获益
|
|
|
|
+ $intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');
|
|
|
|
+ if($intro_uid){
|
|
|
|
+ $score = bcdiv(bcmul($order['total_price'],5,2),100,2);
|
|
|
|
+ if($score > 0){
|
|
|
|
+ $rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'score',$score,3,'直推代理奖励','unishop_order',$order['id']);
|
|
|
|
+ if($rs_wallet['status'] === false){
|
|
|
|
+ echo $rs_wallet['msg'];
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $score = 0;
|
|
|
|
+ //上上级
|
|
|
|
+ $top_uid = Db::name('user')->where('id',$intro_uid)->value('intro_uid');
|
|
|
|
+ if($top_uid){
|
|
|
|
+ $score = bcdiv(bcmul($order['total_price'],1,2),100,2);
|
|
|
|
+ if($score > 0){
|
|
|
|
+ $rs_wallet = $walletmodel->lockChangeAccountRemain($top_uid,'score',$score,4,'兼推代理奖励','unishop_order',$order['id']);
|
|
|
|
+ if($rs_wallet['status'] === false){
|
|
|
|
+ echo $rs_wallet['msg'];
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //订单完成
|
|
|
|
+ $rs_order = Db::name('unishop_order')->where('id',$order['id'])->update(['paidtasktime'=>time()]);
|
|
|
|
+ if($rs_order === false){
|
|
|
|
+ echo '更新失败';
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //循环结束
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ echo '成功';
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|