user_money = bcsub($user->user_money, $order['actual'], 2); $user->save(); Db::commit(); return true; } catch (Exception $e) { Db::rollback(); Log::error('余额支付失败' . $e->getMessage() . '。line:' . $e->getLine() . '。file:' . $e->getFile()); self::setError('余额支付失败' . $e->getMessage()); return false; } } /** * @notes 订单支付成功 * @param $order 订单 * @param $CallbackData 回调数据 * @date 2021/7/8 00:40 */ static function paySuccess($order, $CallbackData = []) { Db::startTrans(); try { $order->money = $CallbackData['money']; $order->paid = 1; $order->save(); Log::info('支付成功'); // 提交事务 Db::commit(); return true; } catch (\Exception $e) { // 回滚事务 Db::rollback(); Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); self::setError('支付失败' . $e->getMessage()); return false; } } /** * 获取用户常用购买记录 */ public static function frequentlyPurchase($params) { try { $goods_id = Cashierinfo::where('uid', Request()->userId)->page($params['page_no'])->limit(50)->column('goods'); if(!$goods_id){ return []; } $goods_arr = array_unique($goods_id); $select = Goods::where('id', 'in', $goods_arr)->with('unitName')->field('id,name,sell,imgs,unit')->select(); return $select->toArray(); } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function purchaseAgain($order_id){ $arr= Cashierinfo::where('pid',$order_id)->field('goods,nums')->select(); $data=[]; foreach ($arr as $k=>$v){ $data[$k]['goods_id']=$v['goods']; $data[$k]['cart_num']=$v['nums']; $data[$k]['uid']=Request()->userId; $data[$k]['source']=0; $data[$k]['mer_id']=0; $data[$k]['staff_id']=0; $data[$k]['is_new']=0; } if($data){ ( new Cart())->saveAll($data); return true; } return false; } }