'ID', 'user_id' => 'User ID', 'log_type' => '类型:1=收入,2=支出', 'type' => '类型:2=余额,1=积分', 'amount' => '变动数', 'desc' => '变动说明', 'before' => '变动前', 'after' => '变动后', 'operator' => '操作者', 'operator_id' => '操作者id', 'operator_type' => '1:前台,2:后台', 'pic_url' => '图片', 'explain' => '说明', 'created_at' => '添加时间', 'order_type' => '订单类型 0--充值 1--商城订单 2--秒杀订单 3--拼团订单 4--商城订单退款 5--秒杀订单退款 6--拼团订单退款 7--后台改动,15、团购券, 23、大转盘抽奖', 'order_id' => '订单ID', 'from' => '是否为转增', 'saas_id' => '联盟用户' ]; } /** * 仅适用客户端使用 * @param $user_id * @param $amount * @param $type * @param $log_type * @param int $order_type * @param int $order_id * @param string $desc * @return bool */ public static function saveLog($user_id, $amount, $type, $log_type, $order_type = 0, $order_id = 0, $desc = "", $from = 0, $from_user_id = 0, $profit = 0) { $form = new self(); $user_info = User::findOne($user_id); $form->store_id = $user_info->store_id; $form->user_id = $user_id; $form->amount = $amount; $form->type = $type; $form->before = $type == AccountLog::TYPE_INTEGRAL ? $user_info->integral : $user_info->money; if ($log_type == AccountLog::LOG_TYPE_INCOME) { if ($type == AccountLog::TYPE_INTEGRAL) { $form->after = $user_info->integral + $amount; } else { $form->after = $user_info->money + $amount; } } else { if ($type == AccountLog::TYPE_INTEGRAL) { $form->after = $user_info->integral - $amount; } else { $form->after = $user_info->money - $amount; } } $form->desc = $desc; $form->order_type = $order_type; $form->order_id = $order_id; $form->operator = ''; $form->operator_id = 0; $form->log_type = $log_type; $form->operator_type = AccountLog::TYPE_OPERATOR_NORMAL; $form->created_at = time(); if ($from) { $form->from = $from; } if ($from_user_id) { $form->from_user_id = $from_user_id; } if ($profit) { $form->profit = $profit; } if ($form->save()) { if ($type == AccountLog::TYPE_INTEGRAL) { if ($log_type == AccountLog::LOG_TYPE_INCOME) { $user_info->integral += $amount; } else { $user_info->integral -= $amount; } } else { if ($log_type == AccountLog::LOG_TYPE_INCOME) { $user_info->money += $amount; } else { $user_info->money -= $amount; } } $save = $user_info->save(); if(!$save){ \Yii::error([__METHOD__, $user_info->getErrors()]); } return $save; } } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if ($insert) { self::wxCardSync($this, $changedAttributes); self::voiceSendMessage($this); } } public static function wxCardSync($form, $ca = []) { \Yii::error([__METHOD__, $form, $ca]); if ($form->type != AccountLog::TYPE_INTEGRAL) { return true; } $cf = new CardForm(); $bind = $cf->getBindByUserId($form->user_id, $form->store_id); if (!$bind) { return true; } $amount = $form->amount; if ($form->log_type != AccountLog::LOG_TYPE_INCOME) { $amount = -$amount; } $cf->updateUser($bind, [ "record_bonus" => $form->desc, "bonus" => $form->after, "add_bonus" => $amount, ]); return true; } // 余额支付语音播报 public static function voiceSendMessage($form) { if ( $form->log_type == self::LOG_TYPE_EXPEND && $form->type == self::TYPE_BALANCE && $form->operator_type == self::TYPE_OPERATOR_NORMAL && $form->order_id > 0 ) { $store = Store::findOne($form->store_id); if ($store && !empty($store->device_name)) { $total_fee = $form->amount; IotCloudHelper::sendMessage($form->store_id, '{"cmd":"voice","msg":"会员卡消费收款'.$total_fee.'元","msgid":"'.$form->created_at . $form->order_id.'"}'); } } } }