123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\command;
- use app\model\Member;
- use app\model\MemberAccount;
- use app\model\Order;
- use app\model\PayDetail;
- use support\Db;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class WelfareAccountCommand extends Command
- {
- protected static $defaultName = 'WelfareAccountCommand';
- protected static $defaultDescription = 'WelfareAccountCommand';
-
- protected function configure()
- {
-
- $this->addArgument('name', InputArgument::OPTIONAL, '福利账户余额清空');
- }
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- $accounts = MemberAccount::where('member_account_classify','WELFARE')->get()->toArray();
- Db::beginTransaction();
- try{
-
- foreach($accounts as $account){
- if ($account['member_account_income'] == '0.00'){
- echo "会员【" . $account['join_account_member_id'] . "】跳过\n";
- continue;
- }
-
- MemberAccount::where('member_account_id',$account['member_account_id'])->update([
- 'member_account_expend' => $account['member_account_expend'] + $account['member_account_surplus'],
- 'member_account_surplus' => 0
- ]);
-
- $this->generatePayDetail($account);
- echo "会员【" . $account['join_account_member_id'] . "】已处理完成\n";
- }
- Db::commit();
- return self::SUCCESS;
- }catch(\Exception $e){
- dump($e->getMessage());
- Db::rollBack();
- }
- }
-
- private function generatePayDetail($account)
- {
- $payDetailData = [
- 'join_pay_member_id'=>$account['join_account_member_id'],
- 'pay_status'=>'SUCCESS',
- 'pay_category'=>'CLEAR',
- 'pay_amount'=>$account['member_account_surplus'],
- 'pay_paytimes'=>date('Y-m-d H:i:s'),
- 'pay_prepayid'=>$account['member_account_nbr'],
- 'pay_addtimes'=>time()
- ];
-
- PayDetail::insert($payDetailData);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private function generateWelfareAccount($memberId)
- {
- $cashAccount = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'CASH')->first();
- if (!$cashAccount) {
- return false;
- }
- MemberAccount::insert([
- 'join_account_member_id' => $memberId,
- 'member_account_classify' => 'WELFARE',
- 'member_account_status' => 'ACTIVED',
- 'member_account_category' => 'NORMAL',
- 'member_account_nbr' => $memberId . '-WELFARE',
- 'member_account_name' => '福利账户',
- 'member_account_income' => $cashAccount->member_account_income,
- 'member_account_expend' => $cashAccount->member_account_expend,
- 'member_account_surplus' => $cashAccount->member_account_surplus,
- 'member_account_added' => $cashAccount->member_account_added,
- 'member_account_addtimes' => time()
- ]);
- return true;
- }
- }
|